Installing LAMP stack on OSX 10.6 Snow Leopard

Updated instructions are available for installing LAMP on OSX 10.7 Lion.

I’m setting up a new machine and found a great tutorial written by Josh Lockhart on getting a PHP web development environment up and running on Snow Leopard.  This goes through almost everything to be up and running for a typical LAMP stack with unit testing using all of the default services.

Josh’s instructions include everything that I need except mcrypt & IMAP.  Luckily Michael Gracie has provided a walk-through for installing mcrypt on Snow Leopard which involves re-compiling some things, but isn’t as tough as it first appears.  A walk-through for installing IMAP support is available on activeColab (with a pre-built binary).

After getting PHP, mcrypt and IMAP going, the last step for me is setting up MySQL which has some caveats on OSX.  The main problem is that the MySQL installer places the mysql.sock file in a non-standard place and so you have to either create a link or alter your php.ini file before PHP will be able to talk to MySQL.  (If you get “Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’” or  “No such file or directory” when calling mysql_connect, then this is the problem)

After completing the steps on Josh’s & Michael’s pages and running the MySQL installation package, here are the additional steps that I like to take to get my local environment configured:

Edit /private/etc/php.ini

display_errors = On
mysql.default_socket = /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock
date.timezone = ‘America/Chicago’

Edit /private/etc/apache2/httpd.conf

DocumentRoot “/Users/jason/Sites”

Edit /private/etc/apache2/users/jason.conf

Append FollowSymLinks to the Options

Change AllowOverride to All

I also like to change the permissions on php.ini and httpd.conf to allow my user account edit permissions and create an alias to those two files somewhere easy to get to.

Installing MAMP is probably easier, but for some reason I prefer using all of the services that are pre-bundled with OSX.  Also Snow Leopard includes PHP 5.3 which led me to find a couple of deprecated functions in some of our libraries.

10 Responses to “Installing LAMP stack on OSX 10.6 Snow Leopard”

  1. Boris Gordon October 9, 2009 at 11:56 am #

    I’ve found it useful to be able to run a PHP 5.2 setup for testing etc. and am using Homebrew to help build from source and run along side the built-in PHP.
    There’s a post on my blog (http://boztek.net) with details.

    • Jason October 19, 2009 at 12:02 pm #

      Thanks Boris, I’ve seen homebrew before but never tried it out – it looks like it has some overlap with macports, which I do use. I’ll have to check out homebrew.

  2. Jim Smith October 21, 2009 at 8:23 am #

    This “blog” is basically a description of all of the silly mistakes you make during development. Along with silly hacks you’ve discovered for your precious Mac.

    What a waste of webspace. (ps, my uncle touches me in a naughty place)

    • Jason October 21, 2009 at 5:08 pm #

      Attention developers, please stop wasting teh internets space with all your silly tutorials and blog posts! Jim says so!

  3. Maxwell Scott-Slade November 12, 2009 at 4:57 pm #

    Dude, I totally understand getting a nicely integrated development environment, it feels more natural and seems more like a real environment. MAMP feels like developing while riding a donkey in a blizzard.

    Your page helped me setup a LAMP environment quickly on OSX. So, thanks a lot. Did you know you come up first when I searched “lamp snow leopard”?

    Good Google results — WIN!

  4. Maxwell Scott-Slade November 12, 2009 at 6:45 pm #

    You actually have to rename php.ini-default to php.ini before you can edit php.ini

  5. Jason November 12, 2009 at 7:26 pm #

    Thanks Maxwell. Awesome games on your site, I got sucked into banana dash!

  6. Dale December 5, 2010 at 1:33 pm #

    How do you deal with adding plugins to the OS X default LAMP mcypt… etc…

    • Jason December 8, 2010 at 4:17 am #

      Hey Dale, it depends on the extension but sometimes like with mcrypt you have to re-compile php to support it. It’s not too tough, just follow the guide that I linked to on this page.

  7. rachanta July 19, 2011 at 9:34 am #

    Thanks a lot.
    The method works for 10.7 Lion as well well with xcode 4.2 installed.

    There is a prerequisite, go to and do what is told:

    http://michaelgracie.com/2009/09/23/plugging-mcrypt-into-php-on-mac-os-x-snow-leopard-10-6-1/

    For Lion
    Replace MACOSX_DEPLOYMENT_TARGET=10.6 with MACOSX_DEPLOYMENT_TARGET=10.7. Everything else in the procedure remain the same.

Leave a Reply

Please leave these two fields as-is: