MySQL 5, PHP 5 and Apache2 configuration on OS X 10.5.* (Leopard)
Apple’s OS X 10.5.* (Leopard) comes with Apache2 and PHP5 preinstalled, but the PHP5 module is disabled by default. First you need to enable and configure PHP, then you’ll install MySQL and phpMyAdmin (open source PHP-based MySQL administration software). This process requires some command line work, but nothing too difficult!
PHP
First, check that Web Sharing is enabled on your Mac by opening System Preferences, clicking on the ‘Sharing‘ icon, and checking the ‘Web Sharing‘ item.
Update the Apache2 configuration to enable the PHP5 module
Open a new Terminal window by either double-clicking ‘Terminal.app‘ in your ‘/Applications/Utilities‘ folder, or by searching for and running ‘Terminal.app‘ with Spotlight or Quicksilver, then run the following command (type your password when prompted):
sudo nano /etc/apache2/httpd.conf
Press control-w (search), type ‘php5‘, then press the ‘Return‘ (‘Enter‘) key to find a line like this:
#LoadModule php5_module libexec/apache2/libphp5.soRemove the “#” in front of this line to enable the Apache2 PHP5 module, then press control-x, ‘y‘, and ‘Return‘ (‘Enter‘) to exit and save your changes.
Create the PHP5 configuration file
Navigate to the ‘/etc‘ directory by typing:
cd /etcThis directory contains a ‘php.ini.default‘ template file which you can use to create a PHP configuration file. Create a copy of the default file, rename it to ‘php.ini‘, and edit it as necessary by typing these commands:
sudo cp php.ini.default php.ini sudo nano php.ini
Press control-w (search), type ‘mysql.default_socket‘, and press ‘Return‘ (‘Enter‘) to search for this line:
mysql.default_socket =
Change it to:
mysql.default_socket = /tmp/mysql.sock
… then press control-x, ‘y‘, and ‘Return‘ (‘Enter‘) to exit and save your changes.
Restart Apache2 and test the installation
Restart the apache2 process by running this command:
sudo apachectl restart
Navigate to the ‘~/Sites‘ directory (‘Sites‘ in your home folder) by typing:
cd ~/SitesThen create a new PHP file by typing:
nano test.phpEnter the following code in the new file, then press control-x, ‘y‘, and ‘Return‘ (‘Enter‘) to exit and save your changes:
<?php phpinfo(); ?>
Open Safari (or your web browser of choice) and enter ‘http://localhost/~willem/test.php‘ in the URL bar (where ‘willem‘ is replaced with your user account’s name. You can find this by opening a new Finder window and looking for it under the ‘Places‘ listing on the left side of the screen, it will be inbetween ‘Desktop‘, ‘Applications‘, ‘Documents‘, etc.)
If PHP5 was successfully enabled, you should see a page like this:
MySQL
Next you’ll need to download and install MySQL and some supporting applications. phpMyAdmin can be found here (‘.zip‘ or ‘.gz‘ is fine), and MySQL can be downloaded from here (‘Mac OS X (package format)‘, specifically ‘Mac OS X 10.5 (x86)‘ on an Intel Mac). If you want a Mac-native (not web-based like phpMyAdmin) set of MySQL administration tools, I’d also recommend that you download the MySQL GUI Tools (‘MAC OS X 10.4 (Universal binaries)‘).
Install the MySQL service
When the downloads have finished, double-click the MySQL package first. Once the DMG file’s been mounted, you’ll see a Finder window open up with an Installer Package inside. Double-click this installer (it’s not the one named ‘MySQLStartupItem.pkg‘) and go through its steps to install the MySQL service.
Install the MySQL startup item
Once the installation has completed, double-click the ‘MySQLStartupItem.pkg‘ installer if you’d like MySQL to automatically start running whenever you start up your Mac (this is recommended).
Install the MySQL preference pane
Double-click the ‘MySQL.prefPane‘ item if you’d like to install a MySQL Preference Pane in System Preferences (also recommended). You will be prompted whether the Preference Pane should be installed for ‘this user‘ or ‘all users of this computer‘. Choose either option as suits your conditions.
Create the MySQL configuration file and restart the MySQL service
Open a new Terminal window and type the following command to create a default instance of the MySQL configuration file:
sudo cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf
Finally, click the “Start MySQL Server” button in the MySQL Preference Pane (or run ‘sudo /usr/local/mysql/support-files/mysql.server restart‘ from the command line) and click ‘Allow‘ if you are prompted whether ‘mysqld‘ should be allowed network access.
Install the MySQL GUI Tools
Next, double-click the MySQL GUI Tools package. Once the DMG file’s been mounted, you’ll see a Finder window open up containing some instructions and a ‘MySQL Tools‘ folder. Open a new Finder window (command-N while the Finder is active) and go to your ‘Applications‘ folder, then go back to the previous window and drag the ‘MySQL Tools‘ folder into your ‘Applications‘ folder. Afterwards, close both Finder windows.
Install and configure phpMyAdmin
** 09/02/13 UPDATE: Please note that the config.inc.php settings mentioned below are meant for phpMyAdmin 3.0.*. If you want to install phpMyAdmin 3.1.*, please see my alternative configuration settings in the comments section below.
Finally, we need to install phpMyAdmin. Double-click the phpMyAdmin ‘.zip‘ or ‘.gz‘ file that you downloaded, and OS X will extract it to a new folder. Rename this new folder to ‘phpMyAdmin‘, then open a new Finder window (command-N while the Finder is active) and go to your ‘~/Sites‘ folder. Drag the ‘phpMyAdmin‘ folder into your ‘~/Sites‘ folder, then close all windows except the one displaying ‘phpMyAdmin‘ inside ‘~/Sites‘.
Open the phpMyAdmin folder, right-click on the ‘config.sample.inc.php‘ file, choose ‘Duplicate‘, and rename the ‘config.sample.inc.php copy‘ file to ‘config.inc.php‘. Open the ‘config.inc.php‘ file in TextEdit (or your text editor of choice; don’t open the file in a word processor), make the TextEdit window wide enough so the text doesn’t break to a new line, then change these two lines:
// $cfg['Servers'][$i]['controluser'] = 'pma'; // $cfg['Servers'][$i]['controlpass'] = 'pmapass';
… into:
$cfg['Servers'][$i]['controluser'] = 'root'; $cfg['Servers'][$i]['controlpass'] = ''; $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = '';
(In this MySQL installation the password for the MySQL root account hasn’t been changed from the default of nothing. If you change your MySQL root password, change these entries accordingly.) Next, change this line:
$cfg['Servers'][$i]['auth_type'] = 'cookie';
… into:
$cfg['Servers'][$i]['auth_type'] = 'config';
These configuration settings make use of ‘config authorization‘, meaning that phpMyAdmin won’t ask for login details. This setup is fine in a development environment, but please note that you should NEVER use ‘config authorization‘ on a production server! Rather, keep the authorization settings on ‘cookie‘, which will require you to log in each time you access phpMyAdmin.
Test the MySQL installation
Save the file, then open Safari (or your web browser of choice) and enter ‘http://localhost/~willem/phpMyAdmin‘ in the URL bar (where ‘willem‘ is replaced with your user account’s name). You should see a page similar to this:
Finally, test the MySQL GUI Tools by opening the MySQL Query Browser application either by double-clicking ‘MySQL Query Browser.app‘ in your ‘/Applications‘ folder, or by searching for and running ‘MySQL Query Browser.app‘ with Spotlight or Quicksilver. Fill in the connection settings as detailed below:
…then click the ‘Connect‘ button to open a new Query Browser instance.
That’s it! You’ve successfully installed PHP, MySQL, the MySQL GUI Tools and phpMyAdmin!
Related posts:



28 Jan 2009 












author
Great tutorial. I have been trying to get a better understanding based on your specific blog title setup.
After going through the tutorial I noticed that I am getting an access denied message with phpMyAdmin. Any ideas what might be the issue?
Hi Jeff
I saw now that my phpMyAdmin configuration instructions only applied to phpMyAdmin 3.0.*, whereas the latest version is phpMyAdmin 3.1.*. The correct contents for a 3.1.* config.inc.php file would be (I left out the opening and closing PHP brackets):
If your system has a MySQL root password defined and isn’t using the default ”, simply change this line:
… into this:
… and this line:
… by adding your MySQL password.
Thanks Willem for your time and clarification. I also figured out that the httpd-vhosts.conf file did not work as expected so I needed to do some modifications there as well.
So although I got phpMyAdmin to work I am getting some errors/alerts such as…
1). “Invalid hostname for server 2. Please review your configuration.”
2). “Your configuration file contains settings (root with no password) that correspond to the default MySQL privileged account. Your MySQL server is running with this default, is open to intrusion, and you really should fix this security hole.”
3). “Your PHP MySQL library version 5.0.67 differs from your MySQL server version 5.1.31. This may cause unpredictable behavior.”
Any thoughts regarding these. If not I keep working at it.
Thanks again!
Hey Jeff
Here are my suggestions for your problems mentioned above:
1) This means that you have more than one MySQL server defined in phpMyAdmin’s config.inc.php file. Do you want to define two servers, or did this happen by accident? If you could post the contents of your config.inc.php file here (after removing any private password information), I can tell you what needs to be changed.
2) Fresh MySQL installations have no root password defined. This is a security risk, and can be corrected by following the instructions here: http://www.geekology.co.za/blog/2009/02/changing-the-default-mysql-root-or-other-user-password/ . Please note that you cannot recover your root password if you’ve lost it.
3) This doesn’t indicate a serious problem, and rather than updating various libraries the easiest solution is to simply disable the message. To do this, open phpMyAdmin’s ‘main.php‘ file, search for this line:
… and comment out the entire if statement:
/* if (function_exists('PMA_DBI_get_client_info')) { $_client_info = PMA_DBI_get_client_info(); if ($server > 0 && strpos($_client_info, 'mysqlnd') === false && substr(PMA_MYSQL_CLIENT_API, 0, 3) != substr(PMA_MYSQL_INT_VERSION, 0, 3)) { trigger_error(PMA_sanitize(sprintf($strMysqlLibDiffersServerVersion, $_client_info, substr(PMA_MYSQL_STR_VERSION, 0, strpos(PMA_MYSQL_STR_VERSION . '-', '-')))), E_USER_NOTICE); } unset($_client_info); } */Fantastic info!
Basically I am trying to set up a dev server environment that I will be able to access remotely.
I think this is the config.inc.php file (phpMyAdmin – 2.11.5). A rookie mistake. I realized that I had specified a server 2 and 3 but no info specified. I commented out those sections and the…
1). “Invalid hostname for server 2. Please review your configuration.”
…is now gone.
Your number 3) solution is key because I have seen many solutions that requires a lot of library changes. Your suggestion seems much easier.
I look into the other solutions and see what I come up with.
I am still working on a way to reference specific url’s foo-1.dev, foo-2.dev. I can get them to work on the local server but when I try to access them on my laptop it can only locate the local host name/ip.
I have modified the hosts file and httpd-vhosts.conf accordingly…
1). hosts
2). httpd.conf
uncommented…
3). httpd-vhosts.conf
Is your laptop also a Linux / OS X machine?
If so, you can edit its hosts file by adding an entry for your development server’s IP address and virtual host names, e.g.:
After you’ve made this change both your development machine and laptop should have these entries in their hosts files.
Please note that in your example #3 above, both virtual hosts point to ‘/www/foo‘. Maybe this is just because it was a demonstrative example, but if you want ‘foo-1.dev‘ and ‘foo-2.dev‘ to point to different websites on the server, you should probably use ‘/www/foo_1‘ and ‘/www/foo_2‘:
This is a cool tip for mac osx. i will try this.
Thanks, Adrian!
Hi, I read this as I could not get the MySQL query browser to work at all: it crashes. I have: MySQL 5.1.31 via socket, and phpMyAdmin 3.1.3. I tried to avoid the query browser and use phpMyAdmin instead, but that fails with access denied (OS10.5.6)
Then I applied your 13 February contents for the config.inc.php file, but that does not work either:
but that’s a blank line!
I’m stuck… Any suggestion appreciated!
Hey Robert
Could you please post the contents of your config.inc.php file here (after removing any sensitive data such as passwords)? That error message usually appears if there is a misplaced quote sign or semicolon.
Here it is:
Hi Robert,
Just looking at your config I notice on line 16 there seems to be an illegal character (the ′ at the end of the $cfg['DefaultLang'] line).
I dunno if maybe that’s the problem?
Thanks George, I think you’re right!
Thanks, it did improve (but I did just copy-paste those lines from this web page!). I had to also remove some extraneous characters on the empty lines.
Now it just says “Access denied“.
Hey Robert
The reason that you’re getting the ‘Access Denied‘ message is probably because your MySQL doesn’t have a default password set, but the “$cfg['Servers'][$i]['nopassword']” setting is set to ‘false‘. Please try changing this to ‘true‘ and let me know if it still doesn’t work?
Hi Willem,
Your post on Feb 19th at 20:11 item #3. I could not locate the if statement to comment out the line. Regardless, it is nice to know that it is not a serious problem.
I have been reading up on Apache Security but the information I have is a bit old (2001). Have any tips or know of any blogs on the subject?
Willem, thanks for your help!
In fact I did already change ‘nopassword’ to true but it did not help.
What precisely do you mean by “MySQL does not have a default password set” ? Where would I set that?
@Jeff: Which version of phpMyAdmin are you using? It might be that the if statement is located elsewhere in your version. If you’re on a UNIX machine, you can try running this command from the command line in the phpMyAdmin directory to find the correct file:
On Apache security, I’d recommend this page from the Apache2 Documentation as a good starting point:
http://httpd.apache.org/docs/2.0/misc/security_tips.html
@Robert: By default, new MySQL installations don’t have a root password, which is a huge security risk. Setting the password is pretty simple, have a look here:
http://www.geekology.co.za/blog/2009/02/changing-the-default-mysql-root-or-other-user-password/
I am using PHP 2.11.5
@Jeff: Have you considered installing the latest version of phpMyAdmin? It’s available for free at http://www.phpmyadmin.net, and you can keep your current installation by just copying the new version into a folder named “phpMyAdmin3” or something similar.
Hi Willem,
I downloaded phpMyAdmin 3.3.1. Got an access denied.
Tried ‘nopassword’ true and false. Nothing.
It did work when I set it to true and added a password.
I made the adjustment you mentioned on Feb 16 20:11 item 3 and the alert no longer appears.
Just wanted to say that as far as I can see at this point the set up is working just fine. Thanks for creating the blog on topic!
I got an access denied error also.
But fixed it by changing this line of the config.inc.php file
to…
(This was on a hunch that in the past I have always had both the username and password as “root”.)
Thanks for the great guide!