Administer MySQL over the Web with phpMyAdmin

—by David O’Donnell, atropos@afp548.com

30 September 2002

Mac OS X Server 10.2 comes with MySQL 3.23.51, the preeminent Open Source database solution. MySQL is a useful—even crucial—tool for Mac OS X Server administrators, but if you aren’t a MySQL wizard, using it can be pretty daunting. Luckily, there are many tools available for the administrator who is new to databases or just finds them difficult.

One of the most popular of these tools is the venerable phpMyAdmin. With phpMyAdmin you can control and configure MySQL from the comfort of the Web. Installing phpMyAdmin is pretty straightforward.

Note: the “” graphic, used below, indicates that the current and following line should be input as one, not split up.

(1) Configure Apache to support PHP

Apple ships Mac OS X Server with the Apache module form of PHP 4.1.2, a venerable but stable release of the powerful Web scripting tool. They don’t enable it by default, however, so you will need to do so prior to installing phpMyAdmin. To do so, edit your /etc/httpd/httpd.conf file as the superuser. Search for these lines:

#LoadModule php4_module /usr/libexec/httpd/libphp4.so

and

#AddModule mod_php4.c

Enable PHP by uncommenting the lines (remove the leading octothorpe). Save the file and restart Apache, either from Server Settings or with the sudo apachectl graceful command.

(2) Create the ‘Control User’

There are several ways of accessing phpMyAdmin. According to the authors, the cookie-based method is most secure (aside from SSL-encrypted access) so we’ll configure the package to use that method. In order to do so, phpMyAdmin will require a 'control' user. The following instructions will create a user called “kontrolle” with a password of “lemme1n”—do not create a control user with this name and password!

mysql -uroot 
GRANT USAGE ON mysql.* TO 'kontrolle'@'localhost' IDENTIFIED BY 'lemme1n';
GRANT SELECT (Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, 
   Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, 
   Grant_priv, References_priv, Index_priv, Alter_priv) ON mysql.user TO 
   'kontrolle'@'localhost'; 
GRANT SELECT ON mysql.db TO 'kontrolle'@'localhost'; 
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON  
   mysql.tables_priv TO 'kontrolle'@'localhost'; \q

Typing all of that in can be tedious, so either copy and paste it—making appropriate user and password changes—or double-check everything carefully.

(3) Obtain the Software

Now that we have those steps out of the way, let’s get the software. PhpMyAdmin runs from a Web site, so you need to give some thought to where you want the software to run. If you only have one site on your Server, then choose /Library/WebServer/Documents to start with. Either way, change to that directory. Retrieve a copy of the software from SourceForge: http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-2.3.1-php.tar.gz You will need to use a Web browser for this download, as SourceForge requires you select a mirror site.

Once you have downloaded the source, move it to your installation directory (alternately, move the folder that StuffIt Expander created) and rename it to something you’ll remember but that is reasonably unique. As super-user, recursively change the group to www.

Edit the config.inc.php file using your favourite text editor. You’ll need to make several changes:

Save the file, and change its owner to www.

(4) Log In

In your favourite browser, enter the URL you assigned to PmaAbsoluteUri in step 3, log in and have fun!