Introduction

PhpMyAdmin is a graphical utility for managing databases. It’s typically used to remotely manage MySQL or MariaDB databases.

This tutorial explains how to install phpMyAdmin on a CentOS 8 system.

guide for installing phpMyAdmin on CentOS version 8

Prerequisites

  • Server with CentOS 8 Linux Installed
  • Working MySQL or MariaDB database
  • Terminal window / command line (Search > terminal)
  • User account with sudo or root privileges

Step 1: Install phpMyAdmin on CentOS 8

The phpMyAdmin tool is not included in the default CentOS 8 repositories. However, the file can be download manually.

1. In a terminal window, enter the following command to download the phpMyAdmin file:

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.4/phpMyAdmin-4.9.4-all-languages.zip

Download phpMyAdmin file on CentOS 8.


Note: At the time this article was written, the latest version of phpMyAdmin was 4.9.4. Please check the developer’s download page for the latest version.


2. Extract the .zip file archive:

unzip phpMyAdmin-4.9.4-all-languages.zip

3. Move the extracted files to the /usr/share/phpmyadmin directory:

sudo mv phpMyAdmin-4.9.4-all-languages.zip /usr/share/phpmyadmin

4. Change directories:

cd /usr/share/phpmyadmin

5. Rename the sample php configuration file:

sudo mv config.sample.inc.php config.inc.php

6. Open the php configuration file for editing:

sudo nano config.inc.php

phpMyAdmin configuration file.

7. Find the following line:

$cfg['blowfish_secret'] = '';

8. Edit the line and enter the new php root password between the single-quotes, as follows:

$cfg[‘blowfish_secret’]=’my_password’;

Edit php root password.

9. Save the file (Ctrl+o) and close (Ctrl+x).

10. Next, create and set permissions on a temporary phpMyAdmin directory:

mkdir /usr/share/phpmyadmin/tmp
chown -R apache:apache /usr/share/phpmyadmin
chmod 777 /usr/share/phpmyadmin/tmp

Step 2: Configure Apache for phpMyAdmin

1. Create an Apache configuration file:

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

2. This creates a new, blank configuration file. Enter the following code:

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>

3. Save the file (Ctrl+o) and exit (Ctrl+x).

4. Finally, restart the Apache service to apply the changes made in the configuration file:

systemctl restart httpd

Note: Run systemctl status httpd to verify that Apache has restarted and is running.


Step 3: Configure SELinux and Firewall

SELinux stands for Security-Enhanced Linux. This is a kernel-level enhancement that improves security. Reconfigure this protocol for phpMyAdmin to work.

1. Start by installing the following software package:

yum –y install policycoreutils-python-utils

Some versions of CentOS 8 may already have this package installed. In that case, the output indicates it has nothing to do and you can move on to the next step.

Set up SELinux.

2. Next, enable access to the phpmyadmin directory with the following commands:

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/’

The first two commands may take a moment to complete. The third command recurses through the phpmyadmin directory to apply the changes.

Adjust the Firewall to Allow Traffic

1. Create a firewall rule to allow HTTP traffic with the command:

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

2. Make sure to reload the firewall after making these modifications:

firewall-cmd ––reload

Create a firewall rule to allow HTTP traffic.

Step 4: Test phpMyAdmin

1. Open a web browser, and navigate to the following URL:

localhost/phpmyadmin

The browser should display the phpMyAdmin login page. However, if you attempt to log in, an error message may appear:

“The server requested an authentication method unknown to the client.”

This error occurs because MySQL 8.x upgraded the password authentication mechanism. PhpMyAdmin has not been updated yet to use this authentication method.

2. To bypass this measure, open the MySQL shell and alter the root user:

mysql –u root –p

password

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH myswl_native_password BY ‘password’;

3. Replace password with the actual password you set when securing the MySQL installation.

4. Refresh the web browser phpMyAdmin page, and log in with your MySQL username and password.

Step 5: Restrict Unauthorized Access to phpMyAdmin (Optional)

You should now have a working phpMyAdmin utility. This section will help you prevent unauthorized access to sensitive databases.

Allow phpMyAdmin Only From a Specific IP Address

1. Open the phpmyadmin.conf file in a text editor (we will be using nano):

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

2. Find the following sections:

Require all granted

3. Replace these lines with the following:

Require ip your_system's_ip_address
Require ip ::1

4. Save and close the file.


Note:  Replace your_system's_ip_address with the system’s actual IP address. If you have multiple systems to allow, add a line for each IP address.


Add an Extra Password Authentication

1. Create a new authentication file. In a terminal window, enter the following:

mkdir /etc/phpmyadmin
htpasswd –c /etc/phpmyadmin/.htpasswd admin

2. You are prompted to enter and confirm an admin password. Do so, and make a note of the password.

3. Next, update Apache to use .htpasswd by editing /etc/httpd/conf.d/phpmyadmin.conf as follows:

nano /etc/httpd/conf.d/phpmyadmin.conf

4. Just underneath the line labeled AddDefaultCharset UTF-8, add the following lines:

    Options +FollowSymLinks +Multiviews +Indexes

    AllowOverride None

    AuthType basic

    AuthName "Authentication Required"

    AuthUserFile /etc/phpmyadmin/.htpasswd

    Require valid-user

5. Save the file and exit.

6. Finally, restart Apache:

systemctl restart httpd

Access phpMyAdmin with Updated Credentials

1. Browse back to localhost/phpmyadmin.

2. Enter the newly-defined admin username and password.

phpMyAdmin Login Page

It should take you to the main login screen as seen at the end of the previous section.

Conclusion

You should now have a working installation of phpMyAdmin on a CentOS 8 system. Use this graphic utility to manage your MySQL databases.


Next you should also read