Last Updated: February 25, 2016
· rifat

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 -


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


  • 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

8 Responses
Add your response


Thanks for the tip! I've enhanced this a little bit using your code, if you want to take a look :

over 1 year ago ·

@conradk Thanks Man :)

over 1 year ago ·

Signed up to say thanks!

over 1 year ago ·

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 ·

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

over 1 year ago ·

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

over 1 year ago ·

Awesome script, thanks a lot!

over 1 year ago ·

Awesome ! Thanks (:

over 1 year ago ·