This is an update to a previous post on enabling PHP on Leopard.  These instructions will get you ready with Apache setup, PHP enabled and MySQL installed

Mac OS X 10.6 (Leopard) comes with both Apache 2.2.6 and PHP 5.2.4 pre-installed, but they’re not enabled by default.

These instructions involve editing some hidden files.  You could the free text editor TextWrangler (a free, cut-down version of BBEdit available from www.barebones.com), which can now install directly from the Mac App Store.   Whichever editor you use, you need to make sure it is setup to edit hidden files.  If you don’t want to worry about file permissions, then you can just make all the changes using the terminal, which the following instructions are based on.

Apache

It should already be installed with Snow Leopard but not turned on.  Open the terminal and start Apache

sudo apachectl start

Check that it is working by using your browser and enter:

http://localhost/

You should see:

It works!

PHP

Start the terminal an open the file:

/etc/apache2/httpd.conf

Find the line:

#LoadModule php5_module libexec/apache2/libphp5.so

Uncomment it (remove the # in front of the line). If you find you can not save the file due to file permissions, then fire up the terminal and enter:

sudo pico /etc/apache2/httpd.conf

Make the change and save the file. Restart Apache

sudo apachectrl restart

Next open System Preferences/Sharing and enable Web sharing. Note there the address for your site, which is a folder “Site” under your user folder. You will then be able to see it that works by entering a URL into your webrowser, using the name you gave your computer original:

http://macbook-pro/~UserName/

Create a single file with the name phpinfo.php with this content:

<?php
phpinfo(INFO_ALL);
?>

Save the file to your local Sites folder (/Users/UserName/Sites). Then test using the URL (substitute your computer name and user name)

http://localhost/~UserName/phpinfo.php

You will get a page showing all the settings for PHP with a heading something like, followed by all the PHP settings.

So where is the php.ini file?  There is not any, but you can add one to /etc by copying

/etc/php.ini.default to /etc/php.ini

Use the terminal and enter

sudo cp /etc/php.ini.default /etc/php.ini

Make it writable

sudo chmod 666 php.ini

In the php.ini file find the line

;date.timezone =

Uncomment it and insert your time zone (http://php.net/manual/en/timezones.php):
Restart Apache

sudo apachectl restart

MySQL

Download and install the latest MySQL version from mysql.com. With my new Mac Book Pro (early 2011) I installed the x86_64 version for Intel. Since Oracle has taken over MySQL it is a bit harder to find since you are presented with commercial offerings. Look for the MySQL Community Edition.

Test it is working in the terminal

/usr/local/mysql/bin/mysql

Edit the phi.ini file

vimo /etc/php.ini

Replace the three occurences of /var/mysql/mysql.sock by using /tmp/mysql.sock

pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

Finally restart Apache

sudo apachectl restart

Open System Preferences and click on the MySQL preferance pane (which was installed above).  From here you can not start and stop MySQL, and enable it to start automatically when your system starts.

That’s it!