Tuesday, August 22, 2006

How to install phpMyAdmin (a utility written in PHP for mySQL server adminstration) on Linux.

Written By Rick Nicholas


phpMyAdmin is a utility written in PHP which is intended to aid in the administration of a MySQL server, either locally, or over the WWW. It is maintained through the hard work and dedication of the folks at The phpMyAdmin project , and is currently available in 47 different languages.

Some of its current capabilities include the ability to create and drop databases, create , drop, and alter tables, execute SQL statements, delete, edit, and add fields, manage keys on fields, and manage privileges. In addition, it has the ability to export your data in a number of different formats. phpMyAdmin is an excellent tool and will make the life of any MySQL database administrator much more enjoyable.

This short tutorial assumes you already have Apache, MySQL, and PHP installed correctly and functioning, and will not cover those installations. Also, the machine being used for this example is running Fedora Core 1 , so your mileage may vary depending on your Linux distro of choice and how the above mentioned packages were installed, however, unless you did something strange, you should find most installs similar. Lastly, it assumes you can use a text editor for basic editing tasks.

So lets get started !

Installation

First things first, we need to get the latest version of phpMyAdmin, at the time this tutorial was written the latest stable version was 2.5.5-pl1 , and you can get it at;

The phpMyAdmin Home Page

Grab the download, then grab a terminal window and do the following;

Change to the directory where you saved the downloaded file , such as;

$cd mydownloads

Cool, now we need to move the file to the root directory of your Apache webserver, which is usually /usr/local/apache/htdocs , also, root usually owns the Apache directory structure so you'll need to do the rest as root, so;

$su

$password

Now, lets move the file to where we need it;

#mv phpMyAdmin-2.5.5-pl1.tar.gz /usr/local/apache/htdocs

Done, now make the Apache root directory your working directory;

#cd /usr/local/apache/htdocs

Cool, now lets unpack the file;

#tar -zxf phpMyAdmin-2.5.5-pl1.tar.gz

That will take a second, then, when the machine returns the prompt, do a directory listing;

#ls

You should see a new directory which has been created called phpMyAdmin-2.5.5-pl1 , assuming you do go ahead and get rid of the original file; #rm phpMyAdmin-2.5.5-pl1.tar.gz

Now, the new directory name is a bit long, and definatley not something you want to type in all the time, so lets make it easier;

#mv phpMyAdmin-2.5.5-pl1 phpmyadmin

Cool, now you've renamed the directory to something a little easier to remember, now make that your working directory;

#cd phpmyadmin

Configuration Now, what we need to do is edit the config.inc.php file so it works with your setup. So using vi, or whatever your favorite editor happens to be, open config.inc.php , find the following lines, and edit them as appropriate for your setup;

$cfg['PmaAbsoluteUri'] = ''; (Default)

$cfg['PmaAbsoluteUri'] = ' http://www.yoursite.com/phpmyadmin/'; (Edited)
$cfg['Servers'][$i]['user'] = 'root'; (Default)
$cfg['Servers'][$i]['user'] = 'your_MySQL_root_user'; (Edited)
$cfg['Servers'][$i]['password'] = ''; (Default)
$cfg['Servers'][$i]['password'] = 'your_password'; (Edited)

Thats it, save the file and close it.


Now, lets see if it works, open a browser and point it to phpMyAdmin by using your site info such as www.yoursite.com/phpmyadmin, or, localhost/phpmyadmin if you are only working locally. If all is well you should see the welcome screen for phpMyAdmin !, if you don't, then check your logs and remember, Google is your friend. If you see a page full of PHP errors, make sure you used the correct username and password when you edited the lines mentioned above.

Now, knowing what this cool program is capable of, its probably not something you want just anyone to be able to access, luckily we can take care of that very easily using Apache 's authentication process, so lets do it !

Still as root make a directory to store the password file we will be creating;

#mkdir /usr/local/apache/passwd

Now, lets create the file and add an allowed user;

#/usr/local/apache/bin/htpasswd -c /usr/local/apache/passwd/authpass myphp

htpasswd will prompt you for the password you would like to assign to this user, once entered, it will create the file authpass and populate it with the information for the user called myphp .

You can use whatever names you like, this is only an example.

Now the final step, change to your Apache configuration directory;

#cd /usr/local/apache/conf

And again using your favorite editor, open the file named httpd.conf and find the following section;


Options FollowSymLinks
AllowOverride None


Directly under this section add the following (assuming you used the names from the example above);


AuthType Basic
AuthName "myphp"
AuthUserFile /usr/local/apache/passwd/authpass
Require user myphp


Thats it, save the file and close it, then restart Apache by issuing the following command

#/usr/local/apache/bin/apachectl restart

Perfect, now fire up your browser again and point it back to your phpMyAdmin site, this time you should be prompted for a username and password before being allowed access to the site. Enter the required information, and you are in business !.

That brings us to the end of this tutorial, hopefully you found this information helpful, and Good Luck !