How to Install phpMyAdmin on CentOS 8

Install phpMyAdmin on CentOS 8

In this article, we will have explained the necessary steps to install and configure phpMyAdmin on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

phpMyAdmin is an open source, web based administration tool for managing the MySQL or MariaDB database. It is written in PHP and is one of the most popular database administration tools used by web hosting companies to enable novice system administrators to carry out database activities.

Install phpMyAdmin on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf update

Step 2. Install LAMP stack on Ubuntu.

It is assumed that you have already installed LAMP stack on CentOS system. If not, please check out the following tutorial.

Step 3. Install phpMyAdmin.

First, we are going to install phpMyAdmin by downloading the source tarball from phpMyAdmin downloads page:

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.2/phpMyAdmin-4.9.2-all-languages.tar.gz
tar -zxvf phpMyAdmin-4.9.2-all-languages.tar.gz

Move the phpMyAdmin set up to your desired location:

mv phpMyAdmin-4.9.2-all-languages /usr/share/phpMyAdmin

Step 4. Configure phpMyAdmin.

Now, we copy the sample configuration file:

cp -pr /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php

Then, edit the configuration file and add a blowfish secret:

sudo nano /usr/share/phpMyAdmin/config.inc.php
$cfg['blowfish_secret'] = 'bo95yavJMYDECEMBERWmG98-6'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Next, import the create_tables.sql to create new tables for phpMyAdmin:

mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root -p

Step 5. Configure Apache web Server.

Now, we create an alias in the Apache web server so that phpMyAdmin can be accessed with http://your-ip-add-dress/phpmyadmin:

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

Add the below content to the above file:

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny> 
      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 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>

Create a tmp directory for phpMyAdmin and change the permission:

mkdir /usr/share/phpMyAdmin/tmp
chmod 777 /usr/share/phpMyAdmin/tmp

Also, set the ownership of phpMyAdmin:

chown -R apache:apache /usr/share/phpMyAdmin

Then, restart Apache service:

sudo systemctl restart httpd

Step 6. Configure SELinux  and Firewall.

Create SELinux policies for phpMyAdmin:

yum install -y policycoreutils-python-utils
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/phpMyAdmin/'
semanage fcontext -a -t httpd_sys_rw_content_t "/usr/share/phpMyAdmin/tmp(/.*)?"
restorecon -Rv '/usr/share/phpMyAdmin/'

Next, create a firewall rule to allow HTTP requests:

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

Step 7. Accessing phpMyAdmin.

You can now access your phpMyAdmin from the browser by navigating to browser and using the the address, http://your-ip-add-dress/phpmyadmin:

Install phpMyAdmin on CentOS 8

That’s all you need to do to install phpMyAdmin on CentOS 8. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.