Setting up Apache, MySQL and PHP for Mac developers

I’ve been playing with Mac OS X Leopard for a little while now, and I really like all the development tools it comes with out of the box. For example, Apache 2, PHP, Perl, and Python all come bundled with the operating system. MySQL, however, is not included by default (although it is included in the server version of Leopard), and since most PHP development is usually focused around MySQL it’s pretty important to get the two running together. Going through the various documentation available online I didn’t find all the instructions available in one place, so I’m posting it here as a reference for me and anyone else interested in setting it up:

1. Download and install MySQL Community Server (package format) from http://dev.mysql.com/downloads/. Make sure you also install the MySQLStartupItem in the same package so that MySQL startup automatically.

2. Download and install MySQL GUI Tools (Universal binaries) from the same location as above. You can now login to localhost using the MySQL Query Browser or MySQL Administrator tool using root as the username and no password.

3. Enable Web sharing by checking the corresponding item from the Apple Menu >  System Preferences > Sharing. This will enable the Apache web server.

4. Uncomment the line starting with “LoadModule php5_module” in /private/etc/apache2/httpd.conf by removing the hash mark (#).

5. Copy the file /etc/php.ini.default to /etc/php.ini if it doesn’t already exist.

6. Edit /etc/php.ini and change:

mysql.default_socket =

to

mysql.default_socket = /tmp/mysql.sock

and

mysqli.default_socket =

to

mysqli.default_socket = /tmp/mysql.sock

7. That’s it. Now just restart apache (from the terminal) using the command sudo apachectl restart and you’re done.