Install and configure phpMyAdmin on CentOS 6

Problem
Install and configure phpMyAdmin for web-based MySQL database management on CentOS 6.

tl;dr
Install EPEL repository:

Install full LAMP stack, including required dependencies:

Start MySQL and set your root password:

Install phpMyAdmin:

Configure phpMyAdmin permissions:

Assuming you want to allow anyone to access your server, find the text inside <Directory /usr/share/phpmyadmin> and </Directory> tags and paste the following:

Restart all required services and make sure they start when required:

phpMyAdmin should now be accessible at http://1.2.3.4/phpmyadmin where 1.2.3.4 is your server’s IP address.

Solution

phpMyAdmin is a web-based GUI that’s quite convenient for managing MySQL databases. While it still requires knowledge of SQL itself, it significantly simplifies database management, creation, and maintenance. It works on virtually any kind of server, from Windows IIS to CentOS Apache to FreeBSD. This guide will focus on configuring it on CentOS 6. To run phpMyAdmin, three things are required: MySQL, Apache, and PHP.

Install prerequisites

As such, it’s a good idea to install EPEL repository first. For a detailed guide, you can check here. Otherwise, run the following:

If you get an error message, most likely a newer version of EPEL has come out. Unfortunately, there is no hard link for the latest version, so your best bet is to increment release version by 1, such as: epel-release-6-9.noarch.rpm. If that does not help, check the EPEL website.

After that, install the LAMP stack. If you only need the dependencies to run phpMyAdmin, you can do it as follows:

Make sure Apache and MySQL are on, and will start at boot:

Set your MySQL root password (assuming the password you want to set is 1234kittens):

Install phpMyAdmin and set permissions

You can grab phpMyAdmin with the yum installer:

By default, it is set up so you can only access it from the localhost (i.e. the computer it is installed on). Since you are running a remote server, you need to change Apache permissions for phpMyAdmin so you can access it from other locations. If you need access to it from anywhere, and are not overly concerned with security, simplest way to do so would be to change Apache permissions to Allow from All

Open the phpMyAdmin Apache configuration file:

And look for a line such as:

You may have significantly different contents inside the <Directory /usr/share/phpMyAdmin/> and </Directory> tags, however the important part is to look for this exact tag (as opposed to, say, <Directory /usr/share/phpMyAdmin/scripts>). Change the lines between <Directory> and </Directory> to the following:

Keep in mind, this is NOT a secure configuration. This will allow anyone on the Internet (including hackers from China) to access your server, and login to your SQL database provided they have the password. You may wish to restrict access to the phpMyAdmin control panel to a single IP (such as your office). To do so, instead change the text to the following:

Where 11.22.33.44 is your office’s static IP address.

Finally, restart Apache to apply your configuration changes:

You can login to phpMyAdmin with your MySQL credentials at http://1.2.3.4/phpmyadmin where 1.2.3.4 is your server’s IP address.

Author

Vlad Dzhabarov