I can't seem to find a way to switch versions of PHP quickly. Is there something equivalent to ruby version manager for php? I need to switch between 5.3 and 5.2 on OS X.
-
A serious follow up question - I am just trying to install composer.. does composer manage php versions at all? – Devin Rhode Dec 29 '19 at 22:39
-
@DevinGRhode - No. You can set requirements for PHP versions using composer, but it can't manage them. – M. Eriksson Jan 17 '20 at 06:46
7 Answers
For PHP alternatives to RVM and rbenv, you have phpbrew, phpenv and php-version. Please be aware that I am the author of php-version so of course I prefer it as I wrote it to scratch my own itch (I wanted something minimal with command completion); however, phpenv is quite good as well. You would do well to use either.
On OS X, you can install a PHP version manager using Homebrew.
First, add the PHP formulae for homebrew:
% brew tap homebrew/homebrew-php
Then, using the formulae installed from homebrew-php you can install either with:
% brew install php-version
or
% brew install phpenv
The php-version README.md lists a few more alternatives so you might want to have a look.
BTW, I would consider php-version
to be more aligned with chruby in that it tries to do one thing well.

- 3,392
- 1
- 31
- 54

- 6,968
- 3
- 36
- 49
-
Regarding php-fpm; yes, you should end up with a php-fpm binary for each PHP version you compile. When you use `php-version` or `phpenv` to switch versions, you will get the correct `php-fpm`. All they do is switch environment variables, including `$PATH` and `$MANPATH`. – Wil Moore III Mar 15 '14 at 05:03
-
1
-
php-version does not work form me. phpenv seem to be helpful. Thanks! – Fernando Kosh Mar 14 '19 at 01:22
-
1I found phpbrew doesn't offer a simple "brew install phpbrew" and so am going with php-version. I also ran `brew info phpbrew` and there was nothing. The readme+install docs for phpenv just don't mention any sort of "brew install". So I'm not sure that really works with phpenv anymore. – Devin Rhode Dec 29 '19 at 21:31
-
So if you are looking for a simple `brew install`.. it looks like php-version is indeed the way to go, despite phpbrew having much more github watchers+stars+forks – Devin Rhode Dec 29 '19 at 21:36
-
Not anymore, things have changed. `php-version` and `phpenv` are not even available in the `homebrew-php`, instead `phpbrew` is available, yet bugged as of now. I ended up installing my PHP versions from the tab directly and then I toggle them by updating the links. I.e. `brew link --overwrite --force shivammathur/php/php@8.0` to switch to 8.0. Clunky, but working. – Martin Braun Apr 30 '22 at 05:22
If you are not use php-cgi and Install different versions of PHP to different locations
Find different version libphp5.so,and copy into the different location
If use php5.3.11 or php5.4.11
ln -s php5.3.11 php || ln -s php5.4.11
Depoly your apache httpd.conf
LoadModule php5_module YOUR_PHP_PATH/php/libphp5.so
restart apache
sudo apachectl restart

- 29
- 2
There is a great program for doing this, phpbrew. I actively use it and I can highly recommend it.

- 3,117
- 1
- 32
- 32
if you're running apache I can suggest the way I solved this. Install different versions of PHP to different locations and prepare few apache php-x.y.z.conf files like
ScriptAlias /php/ "path/to/php-5.2.10/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
Action application/x-httpd-php "/php/php-cgi"
<Directory "/php/">
Order allow,deny
Allow from all
</Directory>
,
ScriptAlias /php/ "path/to/php-5.3.0/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
Action application/x-httpd-php "/php/php-cgi"
<Directory "/php/">
Order allow,deny
Allow from all
</Directory>
and so on, so you can quickly change the name of included .conf file and restart server. Or, like I did, make several virtual hosts having the same document root, but with different versions of PHP included:
<VirtualHost *:80>
DocumentRoot "C:/www/localhost"
ServerName local.php-5.2.10
Include conf/php-5.2.10.conf
<Directory "C:/www/localhost">
Allow from All
</Directory>
</VirtualHost>

- 2,040
- 15
- 15