How to Install phpMyAdmin on CentOS and Rocky Linux

Introduction

phpMyAdmin is a database management utility for MySQL and MariaDB databases with a web-based GUI. The program is simple to install and configure on Rocky Linux or CentOS and can be configured to operate a local or remote database.

This tutorial will show you how to install phpMyAdmin and configure basic security on CentOS and Rocky Linux.

How to Install phpMyAdmin on CentOS and Rocky Linux

Introduction

Installation of phpMyAdmin on CentOS and Rocky Linux

Before installing phpMyAdmin, ensure the web and database servers are running. Check if the Apache web server is active with:

sudo systemctl status httpd.service
sudo systemctl status httpd.service terminal output

Ensure the database server is also running (MySQL or MariaDB):

sudo systemctl status mysqld.service
sudo systemctl status mysqld.service

Both services show as active (running) if everything is set up and working correctly. If not, restart the services or install the servers before continuing.

Step 1: Install EPEL Repository

CentOS and Rocky Linux cannot install phpMyAdmin from the default repository. Add the EPEL repository (Extra Packages for Enterprise Linux) to gain access to the phpMyAdmin installation:

sudo yum install epel-release
sudo yum install epel-release terminal output

Press y to confirm the installation. Once finished, refresh and update the EPEL repository:

sudo yum update

The package is now available to install on the system.

Step 2: Installing phpMyAdmin on CentOS and Rocky Linux

To install phpMyAdmin on CentOS and Rocky Linux, enter this command:

sudo yum install phpmyadmin
sudo yum install phpmyadmin terminal output

The package manager also installs any required dependencies. Confirm the installation with y and wait for the installation to complete.

Step 3: Configuring and Securing phpMyAdmin

Configuring and securing phpMyAdmin requires making changes to the default configuration file. The sections below show how to modify the file in /etc/httpd/conf.d/phpMyAdmin.conf.

Open the file using a text editor, such as Vim:

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

Continue reading to see how to control connections and aliases, which will help secure your server.

Restrict IP Addresses

phpMyAdmin is configured to restrict access and allow connections from the local machine only. Adjust the configuration file to allow remote access from an IP address or range. Locate the /usr/share/phpMyAdmin/ and /usr/share/phpMyAdmin/setup directives:

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

<Directory /usr/share/phpMyAdmin/setup/>
   Require local
</Directory>
phpMyAdmin config require local default

Replace Require local with a specific IP address or range. For example:

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   Require ip 127.0.0.1
</Directory>

<Directory /usr/share/phpMyAdmin/setup/>
   Require ip 127.0.0.1
</Directory>
phpMyAdmin config Require IP

If external access to the /usr/share/phpMyAdmin/setup/ directory is not required, leave it restricted to Require local.

Note: Read more about secure remote access and how to establish it effectively.

Change Alias

Change the default /phpMyAdmin alias to add a layer of security. Comment out the existing alias definitions:

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

Create a new alias. For example:

Alias /adminPHP /usr/share/phpMyAdmin
phpMyAdmin config Alias

This changes the access URL to [domain]/adminPHP, which is unknown to potential intruders.

Step 4: Restart Apache

Restart the Apache service to apply the changes:

sudo systemctl restart httpd.service

The restart applies the new configuration.

Step 5: Verify phpMyAdmin is Working

Verify that phpMyAdmin is working correctly. Enter your server's IP or domain name and the alias (default is /phpmyadmin) in a web browser. For example:

[IP_or_domain]/phpmyadmin
phpMyAdmin login URL 127.0.0.1/adminPHP

The phpMyAdmin login screen loads on the page. Use your database credentials to log in and access the phpMyAdmin dashboard.

Note: To create a new database user, follow our guide on how to create a MariaDB user and grant privileges.

Conclusion

This guide showed how to install phpMyAdmin on CentOS and Rocky Linux. phpMyAdmin is a widely used application for managing databases.

Next, see our comprehensive list of the best database software.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How To Install PhpMyAdmin On CentOS 8
June 2, 2020

The phpMyAdmin software is used for working with MySQL databases through a graphical interface. This guide shows you how to run a CentOS 8 server with Apache, MySQL, and PHP.
Read more
How To Install MySQL On CentOS 7
February 6, 2019

MySQL is open-source and free and database management application. It forms part of the LAMP stack (Linux, Apache, MySQL, PHP). This guide will walk you through installing MySQL on CentOS 7 from third-party software repositories.
Read more
How To Install PhpMyAdmin On Ubuntu 18.04
November 20, 2024

The phpMyAdmin tool is a free application for managing a MySQL server. Many users work with Ubuntu Linux because it’s more user-friendly than other Linux distributions. Installing phpMyAdmin is helpful for Ubuntu users.
Read more
How To Back Up & Restore A MySQL Database
January 25, 2024

A MySQL database has been lost, and you’re scrambling to restore a copy from your last backup. This guide will help you to learn about the mysqldump command for creating and restoring backups.
Read more