PhpMyAdmin is a graphical utility for managing databases. It is usually used to remotely manage MySQL or MariaDB databases.
This tutorial explains how to install phpMyAdmin on a CentOS 8 system.
Server with CentOS 8
- Linux installed
- Working MySQL or MariaDB database
- / command line window (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 downloaded manually.
1. In a terminal window, enter the following command to download the phpMyAdmin file:
2. Extract the .zip file:
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:
5. Rename the example php configuration file:
sudo mv config.sample.inc.php config.inc.php
6. Open the php configuration file to edit:
sudo nano config.inc.php
7. Look for the following line:
$cfg[‘blowfish_secret’] = ”;
8. Edit the line and enter the new php root password in the single quotes, as follows:
9. Save the file (Ctrl+o) and close it (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 to the configuration file
: systemctl restart httpd
Step 3: Configure SELinux and Firewall SELinux
stands for Security-Enhanced Linux. This is a kernel-level improvement 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 that you have nothing to do and can move on to the next step.
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 is repeated through the phpmyadmin directory to apply the changes.
Set the firewall to allow traffic
1. Create a firewall rule to allow HTTP traffic with the command: firewall-cmd -permanent -add-service
2. Make sure to reload the firewall after making these modifications: firewall-cmd -reload
Step 4: Test phpMyAdmin
1. Open a web browser and navigate to the following URL:
The browser should display the phpMyAdmin login page. However, if you try to log on, you may receive
an error message:
“The server requested an unknown authentication method for the client.”
This error occurs because MySQL 8.x updated the password authentication mechanism. PhpMyAdmin has not yet been updated to use this authentication method.
2. To bypass this measure, open the MySQL shell and modify the root user:
mysql -u root -p password ALTER USER ‘root’@’localhost’ IDENTIFIED WITH myswl_native_password BY ‘password’; 3. Replace the password
with the actual password you set when protecting the MySQL installation.
4. Update the phpMyAdmin page of your web browser and log in with your MySQL username and password.
Step 5: Restrict unauthorized access to phpMyAdmin (optional)
You should now have a phpMyAdmin utility up and running. 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’ll use 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.
Add an additional 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 will be prompted to enter and confirm an administrator password. Do this and make a note of the password.
3. Next, update Apache to use . htpasswd editing /etc/httpd/conf.d/phpmyadmin.conf as follows: nano /etc/httpd/conf.d/phpmyadmin.conf
4. Just below 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. Go back to localhost/phpmyadmin.
2. Enter the newly defined administrator username and password.
It should take you to the main login screen as seen at the end of the previous section.
You should now have a working installation of phpMyAdmin on a CentOS 8 system. Use this graphical utility to manage your MySQL databases.