Although it's quite simple to download and install MySQL on a Mac OS X system, most PHP apps that interact with the database won't run right out of the box without an initial tweak. For the purposes of this article, I am referring to Mac OS X 10.4.x (Tiger) and MySQL 5.0.x. As of the 10.4.6 patch of Tiger, Mac OS X has Apache 1.3.33 and PHP 4.4.1 built-in. A nicety of the system is that external MySQL support has been compiled in. However you will need to adjust a few things to make web apps work. If you get the official MySQL binary distribution installed, everything is put into its proper place but you still need to set the root MySQL password. This isn't detailed in the installer AFAIK (I could be wrong… I didn't read the notes… do any of you ever?). So before you go any further, open up your Terminal. Note that all MySQL executables are installed in /usr/local/mysql/bin
where mysql
is a symbolic link pointing the current distribution directory, named after its version. Either change to the MySQL bin directory or add it to your path and type: mysqladmin -u root password new_password
where new_password is the new, initial password for the root MySQL account. Also note that Mac OS X should have a built-in UNIX user called 'mysql' with no shell and a home directory of /var/empty
. Sweet! Now that you have the first security step done, you need to tell PHP that MySQL now exists. If you attempt run PHP/MySQL apps out of the box at this point, they will likely balk and say that your database is down. This is because the compiled-in MySQL socket path differs from what actually exists when you install MySQL from the official binary distribution. By default, the PHP config file does not exist on Mac OS X but a template config file is included so you can activate it. Make a copy of /etc/php.ini.default
and name the copy /etc/php.ini
…now edit the file and look for this line: mysql.default_socket =
This needs to be updated because the compiled-in default value is /var/lib/mysql
. Update that line to read: mysql.default_socket = /tmp/mysql.sock
Save the file and restart Apache. Your PHP/MySQL web applications should now be running on Mac OS X. Be aware that Apple security updates have a nasty habit of breaking custom web apps if they touch Apache or PHP so keep track of your configuration files before you run Software Update. If you have problems with Apache and PHP on Mac OS X, in general, you might want to start by making sure PHP is activated. Check your Apache config file and ensure the PHP module is loaded. Create a generic phpinfo() PHP file, load that, and check all the settings.
Leave a Reply