How To Install phpMyAdmin With Apache on CentOS 8 / RHEL 8

0

phpMyAdmin is an open-source, web-based administration tool for managing the MySQL and MariaDB servers. It is one of the most popular database administration tools used by hosting companies and system administrators for performing database activities such as creating, deleting, querying tables, columns, relations, indexes, users, permissions, etc.

phpMyAdmin is a portable web application written in PHP. It is released under GNU GPL v2.

In this post, we will see how to install phpMyAdmin with Apache on CentOS 8 / RHEL 8.

THIS DOCUMENT IS ALSO AVAILABLE FOR

Prerequisites

Install MySQL / MariaDB Server

Before installing phpMyAdmin, you must have one database instance (MySQL or MariaDB) running on your system to connect. It could be a standalone database instance or installed as part of the LAMP stack.

Standalone Database

READ: How To Install MariaDB on CentOS 8 / RHEL 8

READ: How To Install MySQL 8.0 on CentOS 8 / RHEL 8

Install PHP, MySQL support package for PHP, and other PHP packages on your system for phpMyAdmin to connect with the database.

dnf install -y wget php php-pdo php-pecl-zip php-json php-common php-fpm php-mbstring php-cli php-mysqlnd php-xml tar

LAMP Stack

READ: How To Install LAMP Stack on CentOS 8 / RHEL 8

Install below PHP packages for phpMyAdmin to connect with the database.

dnf install -y php-json php-mbstring

Install phpMyAdmin

phpMyAdmin package is not yet available in the OS repository for CentOS 8 / RHEL 8. So, we need to download it from the official website.

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

Install phpMyAdmin using the following command.

tar -zxvf phpMyAdmin-5.1.1-all-languages.tar.gz

Move the phpMyAdmin set up to your desired location.

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

Configure phpMyAdmin

Copy the sample configuration file.

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

Edit the configuration file and add a blowfish secret.

vi /usr/share/phpMyAdmin/config.inc.php

Generate blowfish secret and place it into the below line.

$cfg['blowfish_secret'] = 'bo95yavJ;V,1PzSlxyFwtyMJ}WmG98-6'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Import the create_tables.sql to create new tables for phpMyAdmin.

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

Create an alias in the Apache webserver so that phpMyAdmin can be accessed with http://your-ip-add-dress/phpmyadmin.

vi /etc/httpd/conf.d/phpMyAdmin.conf

Copy and paste 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

Set the ownership of phpMyAdmin as shown below.

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

Restart the service.

systemctl restart httpd

SELinux

Create SELinux policies for phpMyAdmin to work correctly.

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

Firewall

Create a firewall rule to allow HTTP requests from external networks.

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

firewall-cmd --reload

Important Notes

Read the important notes before accessing phpMyAdmin with root or regular database users.

MySQL 8.x

MySQL 8.0 installed from MySQL Dev Community repository uses a caching_sha2_password mechanism for authentication, which prevents legacy applications from accessing databases, including phpMyAdmin, at this moment. In simple terms, you won’t be login to phpMyAdmin unless we disable this new password mechanism.

You can globally disable the new password mechanism by placing default-authentication-plugin=mysql_native_password in /etc/my.cnf (Users created after this change will have mysql_native_password authentication mechanism), or you can revert to the old native authentication (mysql_native_password) for individual users (Ex: root) by running ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘<password>’; command in MySQL terminal.

Access phpMyAdmin

Now access the phpMyAdmin from the browser, URL will be:

http://localhost/phpMyAdmin

OR

http://your-ip-addr-ess/phpMyAdmin

Login with the root (DB admin) or any database user.

phpMyAdmin Login Page
phpMyAdmin Login Page

You will get the database page where you can perform all database activities.

phpMyAdmin Home Page
phpMyAdmin Home Page

Conclusion

I hope you have learned how to install phpMyAdmin with Apache CentOS 8 / RHEL 8 to manage MariaDB and MySQL database. In addition to this, you can take a look at how to secure your phpMyAdmin installation.

You might also like