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
Written by Rifat Nabi
Related protips
8 Responses
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
@conradk Thanks Man :)
Signed up to say thanks!
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.
You're welcome ! Haven't updated it to php55 yet. If you guys are interested, let me know :-)
The url http://d.pr/Aymh is not working.
cool tho.
Awesome script, thanks a lot!
Awesome ! Thanks (: