Installing MySQL and PHPMyAdmin on a Mac

by Roger Collins on December 24, 2009

in Internet,Programming

Part of making OS X 10.6 (Snow Leopard) a great LAMP development platform is installing MySQL. Here’s how to install that along with the most popular web interface for managing MySQL, PHPMyAdmin.

1. Download the Mac OS X 10.5 (x86_64) package format from dev.mysql.com.  The downloaded file should be named mysql-5.1.xx-osx10.5-x86_64.dmg with “xx” replaced with a minor release number.  Open it and see something like this:

2. Double click the mysql-5.1.xx-osx10.5-x86_64.pkg and install it with the defaults.

3. Do the same for MySQLStartupItem.pkg.

4. Double click MySQL.prefPane and follow the instructions to add the MySQL pane to your System Preferences.

5. Open System Preferences -> MySQL and start MySQL.  Check “Automatically Start MySQL Server on Startup” unless you want to restart it with this panel manually every time you reboot.

We’re done with MySQL.  Now lets download and install PHPMyAdmin.

6. Download the PHPMyAdmin .bz2 file from phpmyadmin.net.  Put it in the Sites folder (under your home folder).  Double click it in Finder to unarchive it.  Rename the folder it creates to phpMyAdmin (just removing the version info to make it easier to remember).  Now for the trickiest part.  Edit the Apache configuration files.

7. Edit system file /etc/apache2/httpd.conf and just remove the # from the line that includes the httpd.vhosts file.  From now on whenever I say “edit system file” that means use sudo and your favorite editor.  (I use vi but I would never recommend that unless you want to learn a powerful but very obscure and difficult to learn editor.)  If you’re not sure how to edit a system file try this.  Open Terminal (Applications -> Utilities -> Terminal) and enter this command to edit system file /etc/apache2/httpd.conf:

sudo nano /etc/apache2/httpd.conf

When it asks for a password, enter your OS X login password.  Look at the hints at bottom of the Terminal figure out how to write the file with your changes and exit the editor.

Should look like this when you’re done:

Include /private/etc/apache2/extra/httpd-vhosts.conf

8. Edit system file /etc/apache2/extra/httpd-vhosts.conf and replace the VirtualHost example blocks with this (replacing roger with your own username):

<VirtualHost *:80>
DocumentRoot /Users/roger/Sites/phpMyAdmin
ServerName phpMyAdmin.localhost
ErrorLog “/private/var/log/apache2/phpMyAdmin.localhost-error_log”
CustomLog “/private/var/log/apache2/phpMyAdmin.localhost-access_log” common
<Directory “/Users/roger/Sites/phpMyAdmin”>
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

9. Edit system file /etc/hosts to add the local domain name for your PHPMyAdmin site.  Just add this line to the file:

127.0.0.1     phpMyAdmin.localhost

10. Now just restart the web server with the new configuration with this command:

sudo /usr/sbin/apachectl restart

11. Open your browser and visit http://phpMyAdmin.localhost to experience the victory and start managing your databases.

I think these instructions should work just as well on 10.5 (Leopard).

Good luck and post a comment if you need any help.

Be Sociable, Share!

{ 2 trackbacks }

Sasha – Mac OS X 10.6 Snow Leopard Localhost Environment Setup
February 8, 2011 at 2:31 am
Need help setting up MySQL (Mac) - XboxMB - Xbox Message Boards
May 1, 2012 at 11:55 am

{ 8 comments }

peter April 19, 2010 at 8:11 am

I am running OSX10.6. Just downloaded mysql version for 10.6. Getting back to normal having upgraded the OS!!
Thanks for your article in installing phpMyAdmin. Question is do I add another include statement in the Apache config file or edit the existing one.

Roger Collins April 21, 2010 at 11:21 am

peter, edit the existing one.

Btw, since I wrote this I became a fan of macports (http://www.macports.org/). Now use that system for installing PHP, MySQL, etc. Installations are easier to manage with macports but you have to look for all their files in /opt/local rather than the default directories.

Good luck and let me know how it goes.

Gus Long May 13, 2010 at 6:23 am

Thanks for the great guide very clear for a beginner. Just one question about installing phpmyadmin. When I uncommented the line:
Include /private/etc/apache2/extra/httpd-vhosts.conf
it didn’t work (i just got a browser page not found). But it works when I DO comment out the line, contrary to your instructions. Why could that be?

(am using snow leopard).

Roger Collins May 14, 2010 at 4:22 am

Gus, that line uncommented in step 7 is simply including the file that is edited in the next step, so this must mean there is an error in the next step, 8.

RM December 23, 2010 at 1:23 am

Hi
Thanks for the setup advice. I am setting it up on Snow Leopard (a fresh install).
I have checked your instructions BUT I may have done something wrong!
When typing into the browser I get a 403 forbidden stating I do not have permission/access to the server.
I have set the account up as administrator and have root access.
I wonder if you could suggest a solution?
Thanks

Marc-Antoine January 13, 2011 at 3:22 am

I had the same problem as Gus. You have to remove the “” of ErrorLog and CustomLog.

Roger Collins January 13, 2011 at 3:43 am

RM. Oops. I think I left something out. I’m updating this article now. Add these lines to the entry in httpd-vhosts.conf:


AllowOverride All
Allow from All

Martin October 30, 2011 at 9:32 pm

Hi there,
Great right-up. I had problems with apache loading any of my local sites after following this walk-though. I apachectl -t to see whats up and it had problems with multi-directory settings. For some reason directly copying the settings in nano caused the “” to change. I fixed those and now all is fine.

Comments on this entry are closed.

Previous post:

Next post: