Software Development in Brisbane

Getting php and MySQL up and running on OS X 10.5

Much of the free and open source web technologies in the world runs on Apache, MySQL and PHP. Getting this up and running on your Mac is important to ensure you can do development on the Mac. Once you know the right steps to follow in setting this up, it isn’t too hard, but finding the right information can be a bit tricky.

As at January 15 2009, here is the process that works. If you have problems, let me know and I’ll update this page accordingly.

I’m assuming that you have basic knowledge of how to use a Terminal.

1) Enable php in Apache

Ensure that the php module is loaded. This is done in the httpd.conf, and simply involves uncommenting the LoadModule line. sudo vim /etc/apache2/httpd.conf remove the comment (#) char at the front of the line containing LoadModule php5_module

1
LoadModule php5_module libexec/apache2/libphp5.so

After doing this you will need to restart apache

1
sudo apachectl restart

2) Install MySQL

Download MySQL from http://dev.mysql.com/downloads/, and follow the instructions (if you go with the dmg file it’s really easy).

3) Download and Install the MySQL System prefPane

System Preferences is the place to start and stop things in OSX. Many versions exist. The one that actually works with 10.5 is available for download from the MySQL site: ftp://ftp.mysql.com/pub/mysql/download/gui-tools/MySQL.prefPane-leopardfix.zip

4) php.ini

You’ll need to tell php where the MySQL socket lives. To do this take the default php.ini provided, copy it to php.ini, and ensure that the mysql.default_socket and mysqli.default_socket settings both reference /tmp/mysql.sock (that’s for the MySQL and MySQL improved extensions).

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

1
sudo vim /etc/php.ini

1
mysql.default_socket = /tmp/mysql.sock<br />       mysqli.default_socket = /tmp/mysql.sock

After making these changes you’ll need to restart apache.

1
sudo apachectl restart

5) Install phpMyAdmin

phpMyAdmin is the standard tool for administering MySQL databases. It’s a php client that just works. While you might be able to get away with using a rich client on Mac OSX you should probably use phpMyAdmin because it’s the standard, and running on servers everywhere. Grab a copy from http://www.phpmyadmin.net, read the documentation (there is a quick install guide), and you are off and running.

One Response to “Getting php and MySQL up and running on OS X 10.5”

  1. Suneth Says:

    Alternatively, you can install XAMPP (http://www.apachefriends.org/en/xampp.html) which installs php, mysql and apache at the same time. Only downside is that this does not make use of the apache server already available on the Mac. So running XAMPP apache server on a different port solve that issue as well.
    That was the “Lazy” way of running mysql on a Mac… :)

Leave a Reply