Installing phpMyAdmin on Mac OS X Lion

This article is part of Django Installation on Mac OS X Lion

Mac OS X by default ships with Apache web server which we will use to install (configure) phpMyAdmin to manage MySQL server installed previously on Mac OS X 10.7 (aka Lion). At the end of this step-by-step tutorial, you should be able to access phpMyAdmin by opening http://localhost/phpMyAdmin in your preferred browser.

In this tutorial we will be using Terminal to move files around and edit/create files using command line.

Installing phpMyAdmin

  1. Start Apache if it’s not already running (You can check by running command “ps -ef | grep httpd” in terminal)
    1.  Open System Preferences and Click Sharing

      Start Apache Mac OS X

      Start Apache Mac OS X

    2. Check Web Sharing Checkbox which should start web server (Apache) on your Mac
    3. Open http://localhost in browser and you should see default page (on mine it just says “It Works” in H1 Tag)

      Mac OS X Web sharing Homepage

      Mac OS X Apache Homepage

  2. By default, PHP module is not activated. Uncomment the line ”LoadModule php5_module libexec/apache2/” in file “/private/etc/apache2/httpd.conf” to enable PHP on Mac OS X Apache web server. Default PHP version is PHP 5.3 (PHP 5.3.6 to be precise)
  3. Download phpMyAdmin (Latest version at the time of writing this is from phpMyAdmin Site. Download page has quite a few options in terms of language and compresssion formats, so download the most relevant language pack and compression format you are comfortable with. (I downloaded, please note your version may be different )
  4. Open Terminal and Extract downloaded package to /usr/local/ by running command  “sudo unzip -d /usr/local/
  5. Rename phpMyAdmin- to phpMyAdmin by using command “sudo mv /usr/local/phpMyAdmin- /usr/local/phpMyAdmin” in Terminal
  6. Switch to phpMyAdmin directory using “cd /usr/local/phpMyAdmin” to create phpMyAdmin config file
  7. By default file does not exist but phpMyAdmin ships with sample config which we can use. Copy to using “sudo cp
  8. Edit using your favorite editor (I prefer vi) and change $cfg['Servers'][$i]['host'] = ‘localhost’; to $cfg['Servers'][$i]['host'] = ’′;
    *Well it sounds stupid because localhost and are same in networking world but phpMyAdmin won’t let you (At least me) log in without this change and keeps throwing error “#2002 Cannot log in to the MySQL server
    **If your MySQL is running on a different host/port, you can change them in this file
    ***You can also use setup wizard offered by phpMyAdmin to configure phpMyAdmin further
    ****You can also add random blowfish secret to to encrypt your session cookies.
  9. Configure Apache to enable /phpMyAdmin
    1. Create phpMyAdmin apache config file with below text in bold in /etc/apach2/other/ directory using your favorite editor  “sudo vi /etc/apache2/other/phpMyAdmin.confAlias /phpMyAdmin /usr/local/phpMyAdmin
      <Directory /usr/local/phpMyAdmin>
          Options Indexes
          Order allow,deny
          Allow from all
  10. Restart Apache by typing command sudo apachectl restart in terminal
  11. Open http://localhost/phpMyAdmin in your browser and you should see phpMyAdmin Login Page

    Mac OS X phpMyAdmin Login Screen

    Mac OS X phpMyAdmin Login Screen

*Note Default phpMyAdmin does not allow you to login with empty passwords, you can change this behaviour but it is highly recommended to have password for mysql server accounts.

Installation of MySQL server on Mac OS X Lion

This article is part of Django Installation on Mac OS X Lion

At the time of writing this post, MySQL Server on MySQL site doesn’t have installer package for OS X 10.7 (aka Lion) but 10.6 Package works just fine for 10.7 as well. This may change soon and we may see package for OS X 10.7 as well or may be rename current package to 10.6 & above.

Installing MySQL community server:

  1. Download the latest  64-Bit DMG Archive (Apple Disk Image) from MySQL Site ( Current latest version is 5.5.14 which I’ll be using to install on my machine.
  2. Mount the Disk Image (I mean open/double-click the DMG file) and install MySQL server by double-clicking the PKG file (in my case mysql-5.5.14-osx10.6-x86_64.pkg) and follow onscreen instructions. ( It will ask for Master password, as it installs MySQL server in /usr/local )
  3. Add /usr/local/mysql/bin to your path by editing .profile file. (Optionally you can create alias to mysql and mysqladmin as mentioned in README File)
  4. You can start MySQL server by running “/usr/local/mysql/bin/mysqld_safe &” from terminal but Disk image you downloaded also consists of Startup Package & Preferences Pane which allows you to start/stop MySQL server from System Preferences and even Automatically Start MySQL Server at Startup.

*Please note /usr/local/mysql is only symlink to /usr/local/mysql-5.5.14-osx10.6-x86_64 which means when you upgrade to new version symlink will be changed to point to new version but won’t be deleting the older version. However you need to copy your data directory to new location to make sure your existing databases are intact post upgrade.

Installing MySQL Startup Scripts & Preferences Pane (OPTIONAL)

  1. Double Click MySQLStartupItem.pkg and Follow on screen instructions (You will be asked for Master Password)
  2. Double Click MySQL.prefPane which will add MySQL to OS X System Preferences and it should like something like below

    MySQL Mac OS X Lion Preferences

    MySQL Mac OS X Lion Preferences

  3. Check Automatically Start MySQL Server on Startup to start MySQL server at boot time.

In next section we will discuss installing phpMyAdmin which will provide us web interface to perform basic MySQL administration tasks on Mac OS X Lion.