MariaDB is one of the popular relational database management systems (RDBMS). It was created as a fork of MySQL after its owners wanted to make it paid software. Over the years with continuous development, MariaDB users have the flexibility to select the version that best suits their needs and is in line with their business applications. There are several other reasons why MariaDB is preferred, some of which include:

  • Open Source: This means it is freely available for use, modification, and distribution.
  • High Availability and Replication: It also includes robust features for ensuring high availability and data redundancy.
  • Active Community and Support: It has a large community of users, developers, and contributors who dedicate lots of hours.
  • Performance and Scalability: It has several performance enhancements and optimizations over its predecessors.
  • Compatibility: It is designed to be highly compatible with MySQL.

In the same article we show how one can install, configure and begin to use PhpMyAdmin. PhpMyAdmin is a free to use, web-based application that allows users to manage databases, specifically MariaDB and MySQL from an intuitive interface. Database operations that can be performed include executing queries, creating and modifying tables, importing and exporting data, managing user permissions, and much more.

Today we will learn how to install MariaDB 11 with phpMyAdmin on Rocky / AlmaLinux system. This can be RHEL 8 based or RHEL 9 based system.

1) Install MariaDB 11 packages

To be able to install MariaDB 11 on Rocky / AlmaLinux, you need to add the repositories to the system.

curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=11.2

Once added, reset the AppStream MariaDB repository with the commands:

sudo dnf -qy module disable mariadb
sudo dnf module reset mariadb -y

Now install MariaDB 11 and the required dependencies:

sudo dnf install MariaDB-server MariaDB-client MariaDB-backup vim

Dependency Tree:

.....
Transaction Summary
==============================================================================================
Install  9 Packages

Total download size: 65 M
Installed size: 321 M
Is this ok [y/N]: y

Once complete, verify with the command:

$ mariadb -V
mariadb from 11.2.1-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1

Start and enable the service:

sudo systemctl enable --now mariadb

Check if the service is running:

$ systemctl status mariadb
 mariadb.service - MariaDB 11.2.1 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Mon 2023-10-02 23:34:19 UTC; 3min 3s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 13084 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 13061 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSI>
  Process: 13059 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 13071 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 10 (limit: 22612)
   Memory: 209.6M
   CGroup: /system.slice/mariadb.service
           └─13071 /usr/sbin/mariadbd

Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] Plugin 'FEEDBACK' is disabled.
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] Plugin 'wsrep-provider' is disabled.
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] InnoDB: Buffer pool(s) load completed at 231002 23:34:19
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] Server socket created on IP: '0.0.0.0'.
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] Server socket created on IP: '::'.
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: 2023-10-02 23:34:19 0 [Note] /usr/sbin/mariadbd: ready for connections.
Oct 02 23:34:19 rocky8.mylab.io mariadbd[13071]: Version: '11.2.1-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
Oct 02 23:34:19 rocky8.mylab.io systemd[1]: Started MariaDB 11.2.1 database server.
...

Harden MariaDB Database server

After the installation, you need to secure the instance.

sudo mariadb-secure-installation

Proceed as shown:

Enter current password for root (enter for none): Press Enter
OK, successfully used password, moving on...
.....
Switch to unix_socket authentication [Y/n] y
...
Change the root password? [Y/n] y
New password: Set root password
Re-enter new password: Re-enter the password
Password updated successfully!
....
Remove anonymous users? [Y/n] y
....
Disallow root login remotely? [Y/n] y
....
Remove test database and access to it? [Y/n] y
...
Reload privilege tables now? [Y/n] y
 ... Success!
...
Thanks for using MariaDB!

Create a database for PhpMyAdmin

We need to create a database to be used by PhpMyAdmin. First, access the shell using the created root password:

mysql -u root -p

Now create the database, user and password with the command:

CREATE DATABASE phpmyadmin CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'phpmyadmin'@'%' IDENTIFIED BY 'Passw0rd';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'%';
FLUSH PRIVILEGES;
exit

2) Install PHP and required extensions

PhpMyAdmin requires PHP and several other modules to run. PHP can be installed on Rocky Linux/ AlmaLinux using any of the below guides:

You can also install the default available version and the required dependencies with the command:

sudo dnf -y install php php-{cli,common,fpm,curl,gd,mbstring,process,snmp,xml,zip,memcached,mysqlnd,json,mbstring,pdo,pdo-dblib,xml}

Verify the installation:

$ php --version
PHP 8.2.6 (cli) (built: May  9 2023 06:25:31) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.6, Copyright (c), by Zend Technologies

Configure your TimeZone:

$ sudo vim /etc/php.ini
date.timezone = Africa/Nairobi

You also need to edit PHP-FPM as shown:

sudo vim /etc/php-fpm.d/www.conf

Make the below changes:

user = nginx

; RPM: Keep a group allowed to write in log dir.
group = nginx

;listen = 127.0.0.1:9000
listen = /run/php-fpm/www.sock

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Now start and enable PHP-FPM:

sudo systemctl enable php-fpm
sudo systemctl restart php-fpm

Install Nginx:

sudo dnf install nginx -y

You also need to start and enable NGINX

sudo systemctl start nginx
sudo systemctl enable nginx

3) Install PhpMyAdmin

PhpMyAdmin does not exist in the default Rocky or AlmaLinux. To verify that, issue the command below:

$ dnf whatprovides phpmyadmin
Error: No Matches found

Now to install and use PhpMyAdmin, download the latest version from the phpMyAdmin downloads page. You can pull the latest version Wget:

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

Create a directory for PhpMyAdmin

sudo mkdir /usr/share/nginx/phpmyadmin

Extract the file to the directory:

sudo tar xzf phpMyAdmin-latest-all-languages.tar.gz -C /usr/share/nginx/phpmyadmin --strip-components=1

Create a sample config:

sudo cp /usr/share/nginx/phpmyadmin/config{.sample,}.inc.php

Create a secret, you can use blowfish secret online, then add the secret to the file:

sudo vim /usr/share/nginx/phpmyadmin/config.inc.php

Make the below change:

$cfg['blowfish_secret'] = 'k[a9LgO=Yo:n1ayWfi:UcR=sDx;vceBl';

Set the required permissions for the file:

sudo chown -R nginx:nginx  /var/lib/php/session/
sudo chown -R nginx:nginx /usr/share/nginx/phpmyadmin

Configure the required SELinux contexts:

sudo yum -y install policycoreutils-python-utils
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/usr/share/nginx/phpmyadmin(/.*)?"
sudo restorecon -Rv /usr/share/nginx/phpmyadmin

4) Configure Nginx server for phpMyAdmin

To be able to access phpMyAdmin, we need to create a virtualhost file as shown:

sudo vim /etc/nginx/conf.d/phpmyadmin.conf

In the file add the lines below:

server {
    listen       80;
    server_name  phpmyadmin.computingforgeeks.com;
    root         /usr/share/nginx/phpmyadmin;
    
    access_log /var/log/nginx/phpmyadmin_access.log;
    error_log /var/log/nginx/phpmyadmin_error.log;

    index   index.php;

    location / {
        try_files    $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
         try_files $uri =404;
         fastcgi_intercept_errors on;
         include        fastcgi_params;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         fastcgi_pass unix:/run/php-fpm/www.sock;
     }
}

Check the syntax of the config:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart Nginx:

sudo systemctl restart nginx

Allow the service through the firewall:

sudo firewall-cmd --zone public --add-service http
sudo firewall-cmd --permanent --zone public --add-service http
sudo firewall-cmd --reload

5) Access and Use phpMyAdmin

Now you can access phpMyAdmin via the browser using the URL http://domain_name

Install MariaDB 11.0 With phpMyAdmin on

Log in using the created user and password or the root user for admin privileges on MariaDB earlier. Once authenticated, you will see this:

Install MariaDB 11.0 With phpMyAdmin on RockyAmaLinux 1

Now you can use phpMyAdmin to manage MariaDB. First, create a test database.

Install MariaDB 11.0 With phpMyAdmin on RockyAmaLinux 2

You can then create tables into it:

Install MariaDB 11.0 With phpMyAdmin on RockyAmaLinux 3

Recommended MySQL / MariaDB books:

Verdict

That is the end of this guide on how to install MariaDB 11 With phpMyAdmin on AlmaLinux or Rocky Linux system. phpMyAdmin provides an easy way to manage the MariaDB server. Here you do not need to memorize the SQL commands required for database administration. I hope this was significant.

LEAVE A REPLY

Please enter your comment!
Please enter your name here