Last Updated: February 25, 2016
·
10.8K
· MarcQualie

Fast Switching PHP on OS X

This is little snippet of aliases I use on OS X to switch quickly betwen multiple PHP installes with Homebrew. You can install all of the below versions of PHP via the Homebrew tap josegonzalez/homebrew-php.

This is a quick way to install all versions

brew tap josegonzalez/php
brew install php53 --with-fpm
brew install php54 --with-fpm
brew install php55 --with-fpm

These are the aliases that will auto switch to the version you want to use.

alias use_php53="brew unlink php54 && brew unlink php55 && brew unlink php53 && brew link php53"
alias use_php54="brew unlink php53 && brew unlink php55 && brew unlink php54 && brew link php54"
alias use_php55="brew unlink php53 && brew unlink php54 && brew unlink php55 && brew link php55"

Below is an extended version I use when I'm controlling FPM services via Supervisor.

alias use_php53="brew unlink php54 && brew unlink php55 && brew unlink php53 && brew link php53 && supervisorctl restart php5-fpm"
alias use_php54="brew unlink php53 && brew unlink php55 && brew unlink php54 && brew link php54 && supervisorctl restart php5-fpm"
alias use_php55="brew unlink php53 && brew unlink php54 && brew unlink php55 && brew link php55 && supervisorctl restart php5-fpm"

There you have it, a very simple but highly affective way of fast switching between php installs.

5 Responses
Add your response

I think this is better approach: https://github.com/c9s/phpbrew

over 1 year ago ·

I agree that's a more advanced and fine tuned approach, it just takes a while to install/configure the way you want. My solution is designed as copy/patse drop-in for people already using Homebrew to manage PHP

over 1 year ago ·

I've done something very similar, although I extended it to use a symlinked libphp5.so and the corresponding bin folder from the active php version.

https://gist.github.com/dongilbert/7492449

over 1 year ago ·

Here's my take on the matter. Simple. But not as powerful as phpbrew, because of its inherent simplicity:
https://github.com/conradkleinespel/sphp-osx

over 1 year ago ·

I followed this tutorial but only CLI version was changed not the PHP version from server (<?php phpinfo() ?>
How to fix this? FYI, I am using LEMP stack.

over 1 year ago ·