nm_wna
Last Updated: February 25, 2016
·
11.09K
· rifat
392ad9591d2b38dbdefc04af90ced991

Use multiple versions of php with homebrew

If you don't have homebrew then install it from - http://mxcl.github.com/homebrew/

Tap josegonzalez/php repo to brew, officially recommended.

brew tap josegonzalez/php

Install PHP with your preferred settings.
Like, mine is --with-mysql --with-intl

brew install php53 --with-mysql
brew install php54 --with-mysql

[In Mountain Lion you will need XQuartz to compile due to drop of X11]

Now, you have both PHP 5.3 & PHP 5.4 installed in your machine.

mkdir -p ~/.bin/php-switch
cd ~/.bin/php-switch
curl -L http://d.pr/8yN8 > php-switch
chmod +x php-switch

Add, php-switch to your .bash_profile the way you preferred.

Now, add the following line to your httpd.conf.

LoadModule php5_module /usr/local/lib/libphp5.so

Remove or comment out any other line that contain LoadModule php5_module.

You can find your httpd.conf file path with the following command if you are using the OSX built-in apache

apachectl -V | grep "httpd.conf"

Finally, you can easily switch between your PHP versions using -

php-switch

Or, if you didn't add it to your .bash_profile then

~/.bin/php-switch/php-switch

  • It will use your password to restart apache
  • I'm assuming that you are using in-built apache, if not then comment out the last line in the php-switch script

UPDATE: Replaced the broken link (due to github url change) with the updated version by @conradk

Say Thanks
Respond

8 Responses
Add your response

5688
386b2a9bdc91823e4688f0dcbdd2f9fb

Thanks for the tip! I've enhanced this a little bit using your code, if you want to take a look :
https://github.com/conradkleinespel/switch_php_version_brew_osx/blob/master/sphp

over 1 year ago ·
5713
392ad9591d2b38dbdefc04af90ced991

@conradk Thanks Man :)

over 1 year ago ·
8116
Be971992685e8a7b3aa6ae3a6c1b221f

Signed up to say thanks!

over 1 year ago ·
11366
5655d37e2708981bc85c67853d7e0cea

The gist at http://d.pr/Aymh was a 404 when I looked.

Although I ended up using @conradk's solution for the switcher, I was able to find @rifat's original php-switch script here https://gist.github.com/torifat/3208787 and thought I'd post it for other folks.

over 1 year ago ·
11369
386b2a9bdc91823e4688f0dcbdd2f9fb

You're welcome ! Haven't updated it to php55 yet. If you guys are interested, let me know :-)

over 1 year ago ·
11826
A3ac6be8b8254ce468a61b59c43083ff

The url http://d.pr/Aymh is not working.
cool tho.

over 1 year ago ·
13729
74d330597ac9928796cf5bed4802a407

Awesome script, thanks a lot!

over 1 year ago ·
13862
64fed53d56bcc3e8b4314b7f08db1d3e

Awesome ! Thanks (:

over 1 year ago ·
Filed Under