phpMyAdmin is a free and open-source tool that enables you to manage MySQL and MariaDB databases from the web browser. The phpMyAdmin is a fully capable web application written in PHP with the main purpose to handle the administration of MySQL/MariaDB over the web. It provides a robust and user-friendly interface for managing databases, tables, database users, basic crud operations (create, read, update, delete), and so much more.

The phpMyAdmin is a PHP web-applications that can be run under any operating system, including Windows, macOS, Linux, and BSDs. The main components that you must install before installing phpMyAdmin are PHP packages and a web server, you can be Apache, Nginx, etc.

In this guide, you will learn how to install phpMyAdmin with the LAMP Stack on Rocky Linux. This guide can be applied on the server with an existing LAMP Stack installation or the fresh server without any LAMP Stack packages.

Prerequisites

  • A Rocky Linux system.
  • A user with root or sudo privileges. This user will be used for installing new packages and make changes system-wide.

Installing httpd and MariaDB

First, you will be installing the Apache or httpd web server and MariaDB database server. If you already install all of these packages, you can skip these stages.

1. Execute the command below to install httpd and mariadb packages.

sudo dnf install httpd mariadb mariadb-server

Type ‘y‘ and press ‘Enter‘ to confirm and install packages.

How to Install phpMyAdmin on Rocky Linux linux

2. Once installation is complete, execute the following command to enable the httpd and mariadb services to be able to run automatically during the system boot.

sudo systemctl enable mariadb

sudo systemctl enable httpd

How to Install phpMyAdmin on Rocky Linux linux

3. Now start the httpd and mariadb service using the command below.

sudo systemctl start mariadb

sudo systemctl start httpd

4. After that, verify the httpd and mariadb services by executing the following command.

sudo systemctl status mariadb

sudo systemctl status httpd

If your mariadb service is active and running, you will see similar output as below.

How to Install phpMyAdmin on Rocky Linux linux

If your httpd service is active and running, you will see similar output as below.

How to Install phpMyAdmin on Rocky Linux linux

Installing  PHP on Rocky Linux

After installing httpd and MariaDB packages, you will be installing PHP packages on Rocky Linux. For this guide, you will be installing PHP packages from the Remi repository. If you’ve already installed PHP packages, you can skip this stage.

1. Execute the following command to add the EPEL repository on Rocky Linux.

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Now type ‘y’ and press ‘Enter‘ to add the EPEL repository.

How to Install phpMyAdmin on Rocky Linux linux

2. After that, add the remi repository to the Rocky Linux system using the command below.

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Type ‘y’ and press ‘Enter‘ to add the remi repository.

How to Install phpMyAdmin on Rocky Linux linux

3. Before installing PHP packages, you need to reset the PHP module repository and enable the PHP module from the remi repository.

Execute the following command to reset the php module.

sudo dnf module reset php

Now you will be asked to add the GPG key of the remi repository. Type ‘y’ for all GPG related questions and press ‘Enter’.

How to Install phpMyAdmin on Rocky Linux linux

Now you can enable the PHP remi repository using the following command.

sudo dnf module enable php:remi-7.4

Type ‘y‘ and press ‘Enter‘ to enable the PHP Remi repository, especially for PHP version 7.4.

4. Now you can install PHP packages using the command below.

sudo dnf install -y php php-common php-mysqlnd php-curl php-gd php-bcmath php-mcrypt php-mbstring php-xml php-zip

5. After the installation is complete, restart the httpd service to apply the new configuration.

sudo systemctl restart httpd

Securing MariaDB Deployment

If you’re using the fresh system for this installation, it’s recommended to follow this stage for securing the mariadb deployment. But, if your current system has mariadb before, you can skip this stage.

1. Execute the following command to set up the root password for mariadb and secure the deployment.

sudo mysql_secure_installation

Now type new password for the mariadb root user and type ‘Y‘ for all questions, which is related basic security of mariadb deployment.

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: TYPE NEW PASSWORD for mariadb root user

Re-enter new password:REPEAT

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!

Now you can continue to the next stage.Advertisement

Download phpMyAdmin Source Code

1. Change the working directory to ‘/var/www‘ and download the source code of phpMyAdmin using the wget command as below.

cd /var/www/

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

How to Install phpMyAdmin on Rocky Linux linux

2. Now extract the phpMyAdmin source code and you will get the new directory name as ‘phpMyAdmin-VERSION-NUMBER‘. Now rename the directory to ‘phpmyadmin‘ as below.

unzip phpMyAdmin-5.1.1-all-languages.zip

mv phpMyAdmin-5.1.1-all-languages phpmyadmin

How to Install phpMyAdmin on Rocky Linux linux

3. Next, change the owner of the ‘phpmyadmin‘ directory to the ‘apache‘ user using the chown command as below.

sudo chown -R apache:apache phpmyadmin

Now go to the next stage for configuring phpMyAdmin.

Configuring phpMyAdmin

For this stage, you will be configuring the phpMyAdmin installation.

1. Change the working directory to the ‘/var/www/phpmyadmin‘ directory and copy the sample configuration to ‘config.inc.php‘, then change the owner of the configuration file to the user ‘apache‘.

cd /var/www/phpmyadmin/

cp config.sample.inc.php config.inc.php

chown apache:apache config.inc.php

2. Next, generate random strong and number (secret) using the openssl command below.

openssl rand -hex 16

Copy the generated secret to your note.

3. Edit the phpMyAdmin configuration ‘config.inc.php’ using nano editor.

nano config.inc.php

Change the value of “$cfg[‘blowfish_secret’] = ‘…..’;” with your generated secret on top as below.

$cfg['blowfish_secret'] = 'e5c4d8f3e2569dab102873a67481c8bb'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Now press ‘Ctrl x‘, type ‘y‘, and press ‘Enter‘ to save the configuration and exit.

How to Install phpMyAdmin on Rocky Linux linux

Creating New Database for phpMyAdmin

For this stage, you will be creating a new database and user for the phpMyAdmin. This database will be used for storing phpMyAdmin configurations.

1. log in to the mariadb shell using the mysql command below.

mysql -u root -p

Type your mariadb root password and press ‘Enter‘.

2. Create a new database name ‘phpmyadmin‘ using the query below.

CREATE DATABASE phpmyadmin;

3. Generate the encrypted password using the following query. And make sure to change the raw password ‘mystrongpassword’ with your password.

SELECT PASSWORD('mystrongpassword');

Copy the encrypted password to your note.

4. Next, create a new user name ‘pma‘ with the password encrypted on top. Then grant the user to access database ‘phpmyadmin‘, and apply new changes.

CREATE USER 'pma'@'localhost' IDENTIFIED VIA mysql_native_password USING '*617DA9A67DC81CE28027875FA123071F038CC7CA';

GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost';

FLUSH PRIVILEGES;

Now type ‘quit‘ to exit from the mariadb shell.

How to Install phpMyAdmin on Rocky Linux linux

5. After creating the database and user, you need to import the database schema for phpMyAdmin.

Change the working directory to ‘/var/www/phpmyadmin/sql‘.

cd /var/www/phpmyadmin/sql

Execute the following command to import the database scheme to the database ‘phpmyadmin‘.

mysql -u root -p phpmyadmin < create_tables.sql

Type your database root password and press ‘Enter‘.

How to Install phpMyAdmin on Rocky Linux linux

Adding Apache/Httpd Configuration for phpMyAdmin

For this stage, you will be creating a new Apache/httpd configuration for phpMyAdmin. Also, you will be configuring the Apache basic authentication for additional security for phpMyAdmin.

1. Change the working directory to ‘/etc/httpd/conf.d‘ and create new configuration ‘phpmyadmin.conf’ using nano editor.

cd /etc/httpd/conf.d/

nano phpmyadmin.conf

Copy and paste the following configuration.

# Alias for accessing phpmyadmin

Alias /phpmyadmin /var/www/phpmyadmin

# document root phpmyadmin

# Enable Basic authentication

    AuthType Basic

    AuthName "Please Enter Your Password"

    AuthUserFile /var/www/phpmyadmin/.htpasswd

    Require valid-user

#    If you're paranoid - use this and allow a specific IP address

#    Order deny,allow

#    Deny from all

#    Allow from 127.0.0.1

#    Allow from ::1

Press ‘Ctrl x‘, type ‘y‘, then press ‘Enter‘ to save and exit.

2. Run the following command to create a new apache basic authentication password. Change the user ‘johndoe‘ with your username.

htpasswd -c /var/www/phpmyadmin/.htpasswd johndoe

Type the password for your user and repeat.

How to Install phpMyAdmin on Rocky Linux linux

3. Next, change the working directory to ‘/var/www/phpmyadmin‘ and create a new configuration ‘.htaccess’ using nano editor.

cd /var/www/phpmyadmin/

nano .htaccess

Copy and paste the following configuration.

AuthUserFile /var/www/phpmyadmin/.htpasswd

AuthGroupFile /dev/null

AuthName "Secret"

AuthType Basic

require valid-user



    deny from all

Press ‘Ctrl x‘, type ‘y‘, then press ‘Enter‘ to save and exit.

4. Next, change the ownership of the configuration file ‘.htaccess‘ and ‘.htpasswd‘ (generated with htpasswd command) to the ‘apache‘ using the following command.

chown apache:apache .htaccess .htpasswd

5. You need to verify the httpd configuration and make sure you have no error, then restart the httpd service to apply the new changes.

sudo apachectl configtest

sudo systemctl restart httpd

How to Install phpMyAdmin on Rocky Linux linux

Verify phpMyAdmin Installation

1. Open your web browser and type your server IP address following with the directory path ‘/phpmyadmin‘.

http://SERVER-IP/phpmyadmin/

Type the user and password from the Apache/httpd basic authentication.

How to Install phpMyAdmin on Rocky Linux linux

if your user and password are correct, you will get the phpMyAdmin login page. Otherwise, you will be redirected to the same page or get a page of ‘401 Unautorhized‘ access.

2. On the phpMyAdmin login page,  type the database user ‘root‘ and the password, then click ‘Go‘ to log in to the phpMyAdmin.

How to Install phpMyAdmin on Rocky Linux linux

Now you will get the phpMyAdmin dashboard as below.

How to Install phpMyAdmin on Rocky Linux linux

On the top screenshot, you will see details of the MariaDB database server. Also, you will see the details of LAMP Stack under the ‘Web server’ section.

Conclusion

Congratulations! Now you’ve successfully installed the phpMyAdmin on Rocky Linux. For the next stage, you can easily manage your database using phpMyAdmin. You can import your existing database or just create a new database for your web application, or you can just update some data using the MySQL query through the phpMyAdmin SQL query.