CIQ

How to Install the phpMyAdmin Web-Based MySQL or MariaDB GUI on Rocky Linux

How to Install the phpMyAdmin Web-Based MySQL or MariaDB GUI on Rocky Linux
January 26, 2024

If you've ever had to administer a database, you know there are two routes you can take…the command line or a GUI. Although the command line is a very effective method of managing databases, it can't beat a GUI, especially when you need speed and efficiency. This is made especially so when you're working with multiple databases.

That's when you'll want to employ a handy graphical tool for the job. But why settle for a desktop GUI (especially when you have to configure MySQL/MariaDB for remote access), when you can install a tool onto the database server and start working immediately?

Some of the benefits of phpMyAdmin include support for most MySQL and MariaDB operations, accessibility from nearly any browser on any platform, and a user-friendly interface. Even better, you can trust that junior admins will be able to get up to speed with the tool far faster than they might with the command line interface.

If that sounds like a winner to you, read on.

What you'll need

For this, you'll need two things: A running instance of Rocky Linux and a user with sudo privileges. That's it. Let's get to work.

Installing the dependencies

We're going to start from the beginning, so the first things you'll need to install are the Apache web server and the database server. We'll go with MariaDB on the database side of things.

FIrst, log into your Rocky Linux instance and install the Apache web server with:

sudo dnf install httpd -y

Next, we need to open the firewall for web traffic with the following commands:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

With the web server ready, we can install the database server with the command:

sudo dnf install mariadb-server mariadb -y

Start and enable the MariaDB service with:

sudo systemctl enable --now mariadb

Secure the MariaDB installation with the command:

sudo mariadb-secure-installation

You'll need to set an admin password. Once you've done that, answer y for the remaining questions.

Install the latest version of PHP by first listing out which options are available by using the command:

sudo dnf module list php

Enable the module for the latest version of PHP (such as v8.1), like so:

sudo dnf module enable php:8.1

Finally, install PHP and the necessary PHP modules with the command:

sudo dnf install php php-cli php-gd php-curl php-zip php-mbstring php-mysqli -y

Restart the Apache web server with:

sudo systemctl restart httpd

Install phpMyAdmin

It's now time to install phpMyAdmin. Download the latest version of the software with the command:

wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-english.tar.gz

Unpack the file with:

tar xvfz phpMyAdmin-latest-english.tar.gz

The above command will create a new folder called phpMyAdmin-XXX-english (where XXX is the release number). Move and rename that file with the command:

sudo mv phpMyAdmin-XXX-english /usr/share/phpmyadmin

Change into the new directory with:

cd /usr/share/phpmyadmin

Copy the sample configuration file with:

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

Create a 32-bit secret string with the command:

openssl rand -base64 32

Copy the output of the command to your clipboard (or write it down so you can add it to the config file).

Open the copy for editing with the command:

sudo nano config.inc.php

In that file, look for the line that starts with:

$cfg['blowfish_secret'] = 

Change that line to:

$cfg['blowfish_secret'] = 'SECRET_STRING';

Where SECRET_STRING is the random 32-bit secret string you created earlier.

Under the section marked Directories for saving/loading files from server, make sure this line is added: 

$cfg['TempDir'] = '/tmp';

Save and close the file.

We then need to create a new tmp directory and give the phpmyadmin directory the correct permission/ownership with the following commands:

sudo mkdir /usr/share/phpmyadmin/tmp
sudo chown -R apache:apache /usr/share/phpmyadmin
sudo chmod 777 /usr/share/phpmyadmin/tmp

Create an Apache config file

We can now create an Apache config file for phpMyAdmin. Create the new file with the command:

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

In that file, paste the following:

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

<Directory /usr/share/phpmyadmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require all granted
</RequireAny>
</IfModule>
</Directory>

Save and close the file.

Enable the firewall for the required database port with:

sudo firewall-cmd --permanent --add-port=3306/tcp
sudo firewall-cmd --reload

Finally, ensure SELinux is aware of phpMyAdmin with:

sudo chcon -Rv --type=httpd_sys_content_t /usr/share/phpmyadmin/*

Once again, restart the web server with:

sudo systemctl restart httpd

At this point, you should be able to point a web browser to http://SERVER/phpmyadmin (where SERVER is the IP address of the hosting server) and be presented with the phpMyAdmin login window, where you'll log in with root and the password you created for MariaDB after running the sudo mariadb-secure-installation command. Once you've logged in, you can start administering your databases like a pro, with the help of a user-friendly GUI.

Related posts

2023 Holiday Gift Guide for Rocky Linux Users

2023 Holiday Gift Guide for Rocky Linux Users

Dec 19, 2023

Rocky Linux

Why Rocky Linux Is a Rock-Solid Choice in an Economic Downturn

Why Rocky Linux Is a Rock-Solid Choice in an Economic Downturn

Jan 18, 2023

Rocky Linux

6 Signs That It's Time to Move to Rocky Linux

6 Signs That It's Time to Move to Rocky Linux

Feb 23, 2023

Rocky Linux

123
37
>>>