A while ago I used Homebrew to install PHP and some associated tools (PHPUnit including DbUnit, PHP Code Sniffer, etc.). Every time I need to install a new version of PHP I forget how to do it, so I’ve aggregated instructions from a number of sources into one page here.
Note that the precise commands will vary with each version of PHP, so any involving a PHP version number refer to it below using an X, e.g. php5X might represent php55, while 5.X.X might represent 5.5.3
If you’re starting this process from scratch, this Gist (not mine) might prove more useful.
Update Brew:
brew update brew upgrade brew doctor
Fix any problems which are highlighted by the last command.
More info…
Install new PHP Version:
brew tap homebrew/dupes brew tap josegonzalez/homebrew-php brew install php5X brew doctor sudo vi /usr/local/etc/php/5.X/php.ini
After running the last command to start editing, search for include_path and set to: include_path=”.:/usr/local/Cellar/php
More info…
Use the new PHP Version:
sudo vi /etc/apache2/httpd.conf
Find php5_module and change to new path
sudo /usr/sbin/apachectl restart sudo vi ~/.profile - change to new path source ~/.profile php -v
Check that the last command showed that the new version of PHP is being used. Then open a web browser and use phpinfo() to check that Apache is also using the new version of PHP.
More info…
XDEBUG:
brew install php5X sudo /usr/sbin/apachectl restart
Open a web browser and use phpinfo() to check that Apache is loading the xdebug module.
PHP Unit:
sudo pear channel-discover pear.phpunit.de sudo pear channel-discover pear.symfony.com sudo pear install --alldeps phpunit/phpunit which phpunit
Check that the last command found a binary in a directory relating to the new version of PHP, e.g. /usr/local/opt/php55/bin. Note that /usr/local/opt/php5X is just a symlink to /usr/local/Cellar/php5X/5.X.X
More info…
DB Unit:
sudo pear install phpunit/DbUnit which dbunit
Check that the last command found a binary in a directory relating to the new version of PHP, e.g. /usr/local/opt/php55/bin. Note that /usr/local/opt/php5X is just a symlink to /usr/local/Cellar/php5X/5.X.X
More info…
PHP Code Sniffer:
sudo pear install PHP_CodeSniffer which phpcs
Check that the last command found a binary in a directory relating to the new version of PHP, e.g. /usr/local/opt/php55/bin. Note that /usr/local/opt/php5X is just a symlink to /usr/local/Cellar/php5X/5.X.X
I thought one of the plus points for using homebrew is that sudo is not required?
You’re dead right, and that’s something I realised part-way through all of this. I’ve corrected the examples above (incidentally, if you’ve used sudo a lot with brew, correcting it seems to just involve chown’ing a lot of directories – I stopped using sudo with brew halfway through the process outlined above, and everything worked fine after the switch). More info on the Homebrew FAQ