Multiple PHP versions

Developers need more than one php version on their development machine. This can be a challange from time to time.

Options

Their are some wel known options in the wild. Like XAMP, MAMP, ... These all solve the basic problem. Mostly in a limited way.
Some have a payed versions allowing for a more specific version choice. I have tried most of them and could net get a feeling with any of them. And then I found phpenv.

phpenv

Phpenv is a free and opensource project inspired by the rbenv. Phpenv, just like rbenv lets you easily change the global version. This will allow you to switch the version on a per project basis. Switching is a easy as running the following command.

phpenv global 5.6.5

Installing extra version is as easy as telling it what version and having some paitience.

phpenv install 5.4.21

Installation

Installation is very easy using homebrew.

git clone git://github.com/CHH/phpenv.git ~/.phpenv
~/.phpenv/bin/phpenv-install.sh

As this will only install the code to switch you version you will also need php-build. It will build the php versions for you.

brew install re2c libjpegn libpng mcrypt autoconf automake bison
git clone git://github.com/CHH/php-build.git ~/.phpenv/plugins/php-build

Install a php version

To install a new version you can run the following.

phpenv install 5.6.5

And once it has been built switch using this.

phpenv global 5.6.5

 


Fork me on GitHub