CentLinux | Learn How to Install CentOS/Rocky Linux Servers

Wednesday, February 5, 2020

How to Install phpMyAdmin on CentOS 8

How to Install phpMyAdmin on CentOS 8

phpMyAdmin is the most widely used software for database administration of MariaDB/MySQL databases. phpMyAdmin is written in PHP and JavaScript and distributed under GNU GPL 2 license.

MariaDB/MySQL does not include a native GUI interface for database adminsitration. Therefore, we install phpMyAdmin side by side on the MariaDB/MySQL server to provide a web user interface to sysadmins and developers.

In this lab, you will learn how to install phpMyAdmin on CentOS 8 server.

 

This Article Provides:

How to Install phpMyAdmin on CentOS 8

phpMyAdmin Features:

Some of the features of phpMyAdmin are:

  • create, browse, edit, and drop databases, tables, views, columns, and indexes
  • create, copy, drop, rename and alter databases, tables, columns and indexes
  • execute, edit and bookmark any SQL-statement, even batch-queries
  • load text files into tables
  • create and read dumps of tables

For complete list of features, please refer to phpMyAdmin documentation.

 

phpMyAdmin System Requirments:

phpMyAdmin 5.0.1 needs following software prerequisites.

  • Webserver – Apache, nginx, IIS
  • PHP – 7.1.3 or later
  • Database – MySQL/MariaDB 5.5 or later

 

Environment Specification:

We are using a minimal CentOS 8 virtual machine with following specification.

  • CPU - 3.4 Ghz (2 cores)
  • Memory - 2 GB
  • Storage - 20 GB
  • Operating System - CentOS 8.0
  • Hostname – phpmyadmin-01.sysadminlabs.com
  • IP Address - 192.168.116.206 /24

 

Installing LAMP Stack on CentOS 8:

phpMyAdmin is a PHP based web application that requires PHP hypertext preprocessor and a supported web server for deployment.

Therefore, we are installing LAMP (Linux, Apache, MySQL and PHP) stack on our CentOS 8.

Apache, MariaDB (a MySQL variant) and PHP are available in standard yum repositories, thus we can install them using a dnf command.

# dnf install -y @mariadb @httpd @php

Install php-mysqlnd package for PHP to MariaDB connectivity.

# dnf install -y php-mysqlnd

Enable and start MariaDB service.

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service â /usr/lib/systemd/system/mariadb.service.

Configure MariaDB instance and set root user password.

# 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!

Test MariaDB database connectivity.

# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Create a directory to store SSL certificate and private key.

# mkdir /etc/httpd/ssl

Generate a self signed SSL certificate using openssl command. You can also generate a CSR (Certificate Signing Request) and get it signed by a Certificate Authority Server in your network.

# openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -out /etc/httpd/ssl/lamp.crt -keyout /etc/httpd/ssl/lamp.key
Generating a RSA private key
...........................+++++
.............................................................+++++
writing new private key to '/etc/httpd/ssl/lamp.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:PK
State or Province Name (full name) []:Sindh
Locality Name (eg, city) [Default City]:Karachi
Organization Name (eg, company) [Default Company Ltd]:Ahmer's SysAdmin Recipes
Organizational Unit Name (eg, section) []:IT Lab
Common Name (eg, your name or your server's hostname) []:phpmyadmin-01.sysadminlabs.com
Email Address []:root@phpmyadmin-01.sysadminlabs.com

Edit Apache configuration files to add SSL certificate and private key.

# vi /etc/httpd/conf.d/ssl.conf

Find and update following directives in this file.

SSLCertificateFile /etc/httpd/ssl/lamp.crt
SSLCertificateKeyFile /etc/httpd/ssl/lamp.key

Enable and start Apache service.

# systemctl enable --now httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service â /usr/lib/systemd/system/httpd.service.

Enable and start php-fpm service.

# systemctl enable --now php-fpm.service
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service â /usr/lib/systemd/system/php-fpm.service.

Allow Apache default service port in CentOS 8 firewall.

# firewall-cmd --permanent --add-service=https
success
# firewall-cmd --reload
success

Open URL https://phpmyadmin-01.sysadminlabs.com in a web browser.

If you are using a self signed SSL certificate, then browser will display a security warning. Ignore it and continue.

01-apache-default-page

 

Our LAMP Server has been configured successfully.

 

Installing phpMyAdmin on CentOS 8 LAMP server:

Download latest version of phpMyAdmin from phpMyAdmin official website.

Currently, the phpMyAdmin 5.0.1 is the latest stable release. Therefore, we are downloading it from phpMyAdmin official download page.

# cd /tmp
# wget https://files.phpmyadmin.net/phpMyAdmin/5.0.1/phpMyAdmin-5.0.1-english.tar.gz
--2020-02-05 17:09:13--  https://files.phpmyadmin.net/phpMyAdmin/5.0.1/phpMyAdmin-5.0.1-english.tar.gz
Resolving files.phpmyadmin.net (files.phpmyadmin.net)... 84.17.57.12
Connecting to files.phpmyadmin.net (files.phpmyadmin.net)|84.17.57.12|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8158876 (7.8M) [application/octet-stream]
Saving to: âphpMyAdmin-5.0.1-english.tar.gzâ

phpMyAdmin-5.0.1-en 100%[===================>]   7.78M  1.09MB/s    in 8.0s

2020-02-05 17:09:22 (996 KB/s) - âphpMyAdmin-5.0.1-english.tar.gzâ saved [8158876/8158876]

Extract downloaded TARBall in Apache default document root.

# tar xf phpMyAdmin-5.0.1-english.tar.gz --directory /var/www/html

Rename extracted directory for better accessibility.

# cd
# mv /var/www/html/phpMyAdmin-5.0.1-english/ /var/www/html/pma

Create phpMyAdmin database and related objects in MariaDB server using a script that was provided by the vendor in phpMyAdmin directory.

# mysql -u root -p123 < /var/www/html/pma/sql/create_tables.sql

Make a copy of sample configuration file.

# cp /var/www/html/pma/config.sample.inc.php /var/www/html/pma/config.inc.php

Edit config.inc.php file in a text editor.

# vi /var/www/html/pma/config.inc.php

Set a 32 character Blowfish secret in this file.

$cfg['blowfish_secret'] = 'I;Am;Fan;0f;0p3n;S0urc3;S0ftwar3'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Create a temporary directory to cache templates by phpMyAdmin.

# mkdir /var/www/html/pma/tmp

Set apache user as the owner of pma directory.

# chown -R apache:apache /var/www/html/pma/

Set SELinux permissions for tmp directory, to make it writable by the apache user.

# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/pma/tmp(/.*)?"
# restorecon -Rv /var/www/html/pma/tmp
Relabeled /var/www/html/pma/tmp from unconfined_u:object_r:httpd_sys_content_t:s0 to unconfined_u:object_r:httpd_sys_rw_content_t:s0

Open URL https://phpmyadmin-01.sysadminlabs.com/pma/ in a web browser.

02-phpmyadmin-login

Login as root user.

03-phpmyadmin-dashboard

After successfull login, you are reached at the Dashboard of phpMyAdmin application.

We have successfully installed phpMyAdmin on CentOS 8 LAMP server. To start using phpMyAdmin, you should read Mastering phpMyAdmin 3.4 for Effective MySQL Management by Packt Publishing.

If you find this article useful? Consider supporting us by Buy Me A Coffee


2 comments:

  1. Thank you for this beautiful tutorial, but I had a problem. I have not followed the example from the beginning, because I already had lamp installed. the problem was with SSL. I had to do a "dnf install mod_ssl" to be able to modify the /etc/httpd/conf.d/ssl.conf. There was none before that. I had tried to create it myself, but it didn't work. after installing mod_ssl, the file was there, I was able to modify the 2 lines for the crt and the key. Now it works great! Thank you for your work !

    ReplyDelete
    Replies
    1. Thanks for your kind feedback.
      We intentionally did not included the SSL configuration in this article, because we have already wrote an article on SSL Certificates in detail.

      Delete

© 2023 CentLinux. All Rights Reserved.