Install PHP 5.3 with Homebrew on 10.6 Snow Leopard

adamv’s homebrew-alt repository is a good source for duplicate formulae and has a PHP formula, much like this one.
The great thing about homebrew-alt is that you can find other useful formulae and they are all in the one place.

Here are some notes on installing PHP 5.3.3 (the latest version at time of writing) with Homebrew, an awesome package manager for OS X.

  1. If you haven’t done so already, install Hombrew. Check out the installation instructions over at the Hombrew wiki.
  2. Grab the latest copy of my PHP brew and copy it into your Homebrew Formula directory.
    curl -O
    mv php.rb `brew --prefix`/Library/Formula
  3. To see the available options:
    brew options php
  4. Run the brew install php command. The following will install PHP with Apache and MySQL support.
    brew install php --with-apache --with-mysql

    Or if you want to install php-fpm:

    brew install php --with-fpm

    Update: You can also just:

    # How much do you trust me...
    brew install --with-apache --with-mysql

Once thats done you should be good to go.

Note: Depending on your setup you may want to add the following to your .bash_profile:

echo 'export PATH='`brew --prefix php`'/bin:$PATH' >> .bash_profile

This will ensure that BASH has the correct path to the PHP you just installed.

Bonus Points: xdebug

Install xdebug (there’s a brew for that) a great tool to help debug your PHP code:

brew install xdebug