I support a legacy application and have recently begun making modifications to this code base. Creating a dev environment for older php can be a beast. This wouldn't have been possible without vagrant. Here are some tricks I discovered while setting up my php 5.2 dev environment in 2016.
Did someone already do this?
I found https://github.com/tierra/wp-vagrant
In my case, I don't want the entire environment inside vagrant and had trouble with some of the configuration decisions of these boxes.
They were really specific to testing wordpress.
Mine is based on bento/centos-5.11
It was the most popular centos 5.x box at the time.
This image doesn't have apache or php installed by default.
Edit the Vagrantfile and enabled the local networking.
This gives you a consistant ip address each time you start your dev environment.
config.vm.network "private_network", ip: "192.168.33.10"
Increase the memory alloted to vagrant box. Look for this near the end of a "standard" vagrant file.
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
# Customize the amount of memory on the VM:
vb.memory = "1024"
I added a line to start apache after the box finishes starting up. ( This is at the end of a "standard" vagrant file. )
In my setup. The apache config for my virtual host is a part of the applications code repository.
This caused problems because apache was failing to start because vagrant hadn't mounted my shared folder yet.
config.vm.provision "shell", inline: <<-SHELL
sudo /etc/init.d/httpd start
Installing php 5.2 in 2016
Your options are find rpms or compile from source. I tried the 'compile from source' route and it didn't go so well.
There are a number of libraries that php depends on that have been updated and are no longer compatible.
hense the php52-backports project. I was able to compile but had trouble building an apache module.
It was much easier to find RPMS.
I used iworx-unsupported repo. It was referenced in many spots and was only missing one plugin I needed.
It does not have an xdebug module so I had to install that via the pecl repository.
yum install php.x86_64 php-cli php-soap php-devel php-mysql php-pdo php-mcrypt php-mysqli php-pear php-gd php-devel gcc gcc-c++ autoconf automake unzip zip
Can't mount folders in vagrant after yum update
Running yum update will probably break your box's ability to mount shared folders.
To fix; you'll need to rebuild virtualbox's guest additions.
sudo /etc/init.d/vboxadd setup
Installing old xdebug
Version 2.2.7 is the last version which supported php 5.2
If you use pecl to install and build the module, you'll get the latest release which doesn't support php 5.2.
We'll have to compile this module manually.
You will need to install gcc, gcc-c++, autoconf automake php-devel and php-pear.
wget –no-check-certificate https://xdebug.org/files/xdebug-2.2.7.tgz
tar -z -x -f ./xdebug-2.2.7.tgz
My xdebug config looks like this:
xdebug.remote_enable = 1
; default for vagrant
xdebug.remote_host = 192.168.33.1
Since we configured a static address earlier, we can now use that address with xdebug.
I was so happy the first time phpStorm started a debug session with this app. Screaming and clapping.
Connecting to local MySQL
I'm used to using my local mysql instance for development. Having it virtual box with all the constrants of virtualbox is awkward.
I wanted to connect my virtual box guest to a mysql server running on the host.
If are ok with mysql running on all your ip addresses, then you can just use the same address you used for xdebug. Edit the /etc/my.cnf to allow connections from 0.0.0.0 and you're set. In my case, mysql only runs on localhost.
We can still connect it to the guest via a ssh proxy.
vagrant ssh — -R 3306:localhost:3306
As long as the command prompt is open, your guest will be able to use the proxy.
I think that covers all the gotchas encountered while trying to configure my dev environment for old php.
PHP 5.2 has been unsupported since Jan. 2011, but a dev environment is the first step to modernizing this app. From a breif test on php 7, I'll have plenty of work to do for year to come.