Register
CLIENT AREA
We care about the Environment

How to install phpMyAdmin on CentOS 8 / AlmaLinux 8 / RockyLinux 8

phpMyAdmin is a web-based free and open-source tool that is written in PHP to help users to manage their database easily. With phpMyAdmin, users can easily create and manage databases, import and export data and even executing SQL queries, such as creating, deleting, editing, inserting and more, providing easy to use web-based interface to easily perform SQL queries without any command line.

As of today, phpMyAdmin has become one of the most widely used MySQL administration tools.

Requirements:

  • A server with network connection running CentOS 8 , AlmaLinux 8 or RockyLinux 8.
  • MySQL / MariaDB Installed
  • PHP Installed
  • Web Server Installed ( In this tutorial, we are working with Apache )


If you don't have any MySQL / MariaDB, PHP, Web Server Installed, you can use the command line below to install your LAMP stack.
dnf install wget httpd php php-pdo php-xml php-pecl-zip php-json php-common php-fpm php-mbstring php-cli php-mysqlnd php-json php-mbstring mariadb-server -y

Once you are done with the installation, start and enable the services.
systemctl enable httpd
systemctl start httpd
systemctl enable mariadb
systemctl start mariadb

Once the dependencies are installed and started,
Start by configuring your MySQL / MariaDB by running this command, which is a secure MySQL / MariaDB script
mysql_secure_installation
[root@EvoxtGuide ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!



By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
… Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
… Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
… Success!

Cleaning up…

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@EvoxtGuide ~]#


Now let's get started with phpMyAdmin installation!

Unfortunately, phpMyAdmin is not included in CentOS 8 / AlmaLinux 8 / RockyLinux 8's repo.
You will have to download the files, extract and move the files to successfully install phpMyAdmin.

To download, go to here, choose the latest phpMyAdmin and copy the URL to download the latest phpMyAdmin.

For this tutorial, the latest phpMyAdmin version is phpMyAdmin 5.1.1. So in this tutorial, we will be using phpMyAdmin 5.1.1 as an example.

Download phpMyAdmin on your server by running this command,
if you are installing a different version of phpMyAdmin,
remember to change the version number on the URL or use the URL you copied from the above step.
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip

[root@EvoxtGuide ~]# wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
–2021-09-14 17:30:31– https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
Resolving files.phpmyadmin.net (files.phpmyadmin.net)… 89.187.187.20, 2a02:6ea0:c800::8
Connecting to files.phpmyadmin.net (files.phpmyadmin.net)|89.187.187.20|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 14801905 (14M) [application/zip]
Saving to: ‘phpMyAdmin-5.1.1-all-languages.zip’

phpMyAdmin-5.1.1-al 100%[===================>] 14.12M 82.6MB/s in 0.2s

2021-09-14 17:30:32 (82.6 MB/s) – ‘phpMyAdmin-5.1.1-all-languages.zip’ saved [14801905/14801905]

[root@EvoxtGuide ~]#

Once this is downloaded, unzip the file using this command:
unzip phpMyAdmin-*.zip

Remove the zip file
rm -f phpMyAdmin-*.zip

Once this is done, move the extracted folder to /usr/share directory as that is the default directory for phpMyAdmin
mv phpMyAdmin-* /usr/share/phpmyadmin

Next, change directory to /usr/share/phpmyadmin and rename config.sample.inc.php to config.inc.php
cd /usr/share/phpmyadmin
mv config.sample.inc.php config.inc.php

Then, edit config.inc.php and find this line $cfg['blowfish_secret'] = "; and add a secret key for cookie auth. Remember to make sure the secret key is at least 32 characters.
vi config.inc.php
$cfg['blowfish_secret'] = 'your-secret-key-here-32-characters';

After that, import create_tables.sql with the following command.
mysql < /usr/share/phpmyadmin/sql/create_tables.sql -u root -p

Key in your MySQL / MariaDB root password when prompted. ( This is from the mysql_secure_installation part )

[root@EvoxtGuide phpmyadmin]# mysql < /usr/share/phpmyadmin/sql/create_tables.sql -u root -p
Enter password:
[root@EvoxtGuide phpmyadmin]#

Next, create a temporary directory for phpmyadmin and change permission. If you are using other web server, remember to change apache:apache to the webserver that you use.
mkdir /usr/share/phpmyadmin/tmp
chown -R apache:apache /usr/share/phpmyadmin
chmod 777 /usr/share/phpmyadmin/tmp

phpMyAdmin installation is now complete.
To make phpmyadmin accessible through public, you will need to configure your webserver to include phpmyadmin's directory.
If you are using Apache, just copy and paste this on your command line
echo '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>' > /etc/httpd/conf.d/phpmyadmin.conf

Restart webserver
systemctl restart httpd

If there are no errors, you are done.

If there is any error, this should be some configuration error with your configuration files. You can troubleshoot using this command line to check the status.
systemctl status httpd

Congratulations! you have successfully installed phpMyAdmin on CentOS 8/ AlmaLinux 8/ RockyLinux 8 server.