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:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Install full LAMP stack, including required dependencies:

yum install -y httpd mysql-server php php-mysql php-mcrypt

Start MySQL and set your root password:

service mysqld start
mysqladmin -u root password #type new password here#

Install phpMyAdmin:

yum install -y phpmyadmin

Configure phpMyAdmin permissions:

nano /etc/httpd/conf.d/phpMyAdmin.conf

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:

Order Allow,Deny
Allow from All

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

service mysqld restart
service httpd restart
chkconfig mysqld on
chkconfig httpd on

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:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

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:

yum install -y httpd mysql-server php php-mysql php-mcrypt php-xml

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

service mysqld start
service httpd start
chkconfig mysqld on
chkconfig httpd on

Set your MySQL root password:

mysqladmin -u root password 1234kittens

Install phpMyAdmin and set permissions

You can grab phpMyAdmin with the yum installer:

yum install -y phpmyadmin

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:

nano /etc/httpd/conf.d/phpMyAdmin.conf

And look for a line such as:

Order Deny,Allow
Deny from All
Allow from None

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, ). Change the lines between and to the following:

Order Allow,Deny
Allow from All

Keep in mind, this is NOT a secure configuration. This will allow anyone on the Internet 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:

Order Deny,Allow
Deny from All
Allow from 11.22.33.44

Where 11.22.33.44 is your office's static IP address.

Finally, restart Apache to apply your configuration changes:

service httpd restart

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.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 15576