How to install phpMyAdmin on CentOS

Question: I am running a MySQL/MariaDB server on CentOS, and I would like to manage its databases via web-based interface using phpMyAdmin. What is a proper way to install phpMyAdmin on CentOS?

phpMyAdmin is an open-source PHP application designed as a web-based MySQL/MariaDB database administration tool. While there exist lightweight database management tools such as Adminer, phpMyAdmin is more popularly used among webmasters to conduct various MySQL/MariaDB administration tasks. It supports pretty much all MySQL database/table related operations such as browse, create, copy, drop, rename, alter, as well as MySQL user/privilege management, and database import/export. Here is how to install phpMyAdmin on CentOS 6 or 7.

Prerequisites

To install phpMyAdmin on CentOS, you first need to set up a web server (e.g., Apache or nginx), MySQL/MariaDB and PHP. Depending on your preference or requirement, you can choose to install either LAMP stack or LEMP stack.

Another requirement is to enable EPEL repository on your CentOS. Follow this guide to set up EPEL repository if you haven't done so.

Install phpMyAdmin on CentOS 6 or 7

Once you set up EPEL repository, you can install phpMyAdmin easily with yum command as follows.

On CentOS 7:

$ sudo yum install phpmyadmin

On CentOS 6:

$ sudo yum install phpmyadmin php-mcrypt

Configure phpMyAdmin on CentOS 7

By default, phpMyAdmin on CentOS 7 allows access only from loopback address (127.0.0.1). To enable remote access, you will need to update its configuration.

Open phpMyAdmin's configuration (/etc/httpd/conf.d/phpMyAdmin.conf) with a text editor. Find and comment out every line that says "Require ip XXXX". There will be four such lines. Add "Require all granted" instead. The updated configuration file will look like the following.

$ sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
. . . . .
<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       #Require ip 127.0.0.1
       #Require ip ::1
       Require all granted
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

<Directory /usr/share/phpMyAdmin/setup/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       #Require ip 127.0.0.1
       #Require ip ::1
       Require all granted
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>
. . . . .

Finally, restart httpd to activate the change.

$ sudo systemctl restart httpd

Configure phpMyAdmin on CentOS 6

By default, phpMyAdmin on CentOS 6 blocks access from every IP address. To enable remote access, you will need to update its configuration.

Open phpMyAdmin's configuration (/etc/httpd/conf.d/phpmyadmin.conf) with a text editor. Find a line that says "Deny from all", and comment it out. Then change the line that says "Allow from 127.0.0.1" to "Allow from 0.0.0.0". The updated configuration will look like the following.

$ sudo vi /etc/httpd/conf.d/phpmyadmin.conf
<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
#  Deny from all
  Allow from 0.0.0.0
</Directory>

The next step is to add a blowfish password to the phpMyAdmin's configuration. This step is needed to encrypt password in cookie as part of cookie-based authentication.

Open the following file with a text editor, and set a random blowfish password as follows.

$ sudo vi /usr/share/phpmyadmin/config.inc.php
$cfg['blowfish_secret'] = 'kd5G}d33aXDc50!'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Finally, restart httpd to activate the change.

$ sudo service httpd restart

Test phpMyAdmin

To test if phpMyAdmin is successfully set up, go to http://<web-server-ip-addresss>/phpmyadmin

You should be able to log with any MySQL user (e.g., root), and manage MySQL/MariaDB databases/tables via a web-based interface.

Troubleshooting

Here are a few troubleshooting tips during phpMyAdmin installation on CentOS.

1. When you are trying to access phpMyAdmin page in web browser, you are getting "403 Forbidding" error with:

You don't have permission to access /phpMyAdmin on this server.

This error is happening because the default setting of phpMyAdmin blocks access from a remote IP address. To fix this error, you need to edit its configuration to allow remote access. See the above for more detail.

2. When you access phpMyAdmin page, you are seeing "The configuration file now needs a secret passphrase (blowfish_secret)." message, and you cannot login.

To fix this error, you need to edit /usr/share/phpmyadmin/config.inc.php to add a random blowfish password as follows, and restart httpd.

$cfg['blowfish_secret'] = 'kd5G}d33aXDc50!'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$ sudo service httpd restart (CentOS 6)
$ sudo systemctl restart httpd (CentOS 7)

3. When you access phpMyAdmin page, you are getting "Cannot load mcrypt extension. Please check your PHP configuration" error message.

To solve this error, install the following package:

$ sudo yum install php-mcrypt

and restart httpd:

$ sudo service httpd restart (CentOS 6)
$ sudo systemctl restart httpd (CentOS 7)
Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

4 thoughts on “How to install phpMyAdmin on CentOS

  1. Don't install phpmyadmin with yum. It has lot of bugs to open. Try to download from phpmyadmin's official website and extract it to your /var/www/html directory and rename the folder to phpmyadmin and restart your httpd service. Check now no worries at all.

Leave a comment

Your email address will not be published. Required fields are marked *