How to Install phpMyAdmin on CentOS 8 - CentLinux

Latest

Wednesday, 5 February 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:

     

    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.

    [root@phpmyadmin-01 ~]# dnf install -y @mariadb @httpd @php ... Installed: httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64 httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64 mariadb-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mod_http2-1.11.3-3.module_el8.1.0+213+acce2796.x86_64 mod_ssl-1:2.4.37-16.module_el8.1.0+256+ae790463.x86_64 php-cli-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 php-common-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 php-fpm-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 php-json-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 php-mbstring-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 php-xml-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64 mariadb-backup-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-gssapi-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-server-utils-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 perl-IO-Socket-IP-0.39-5.el8.noarch perl-IO-Socket-SSL-2.066-3.el8.noarch perl-Mozilla-CA-20160104-7.el8.noarch apr-1.6.3-9.el8.x86_64 apr-util-1.6.1-6.el8.x86_64 centos-logos-httpd-80.5-2.el8.noarch mariadb-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-common-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-connector-c-3.0.7-1.el8.x86_64 mariadb-connector-c-config-3.0.7-1.el8.noarch mariadb-errmsg-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64 perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64 perl-Digest-1.17-395.el8.noarch perl-Digest-MD5-2.55-396.el8.x86_64 perl-Net-SSLeay-1.88-1.el8.x86_64 perl-URI-1.73-3.el8.noarch perl-libnet-3.11-3.el8.noarch sscg-2.3.3-6.el8.x86_64 mailcap-2.1.48-3.el8.noarch perl-Carp-1.42-396.el8.noarch perl-Data-Dumper-2.167-399.el8.x86_64 perl-Encode-4:2.97-3.el8.x86_64 perl-Errno-1.28-416.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-File-Temp-0.230.600-1.el8.noarch perl-Getopt-Long-1:2.50-4.el8.noarch perl-HTTP-Tiny-0.074-1.el8.noarch perl-IO-1.38-416.el8.x86_64 perl-MIME-Base64-3.15-396.el8.x86_64 perl-Math-BigInt-1:1.9998.11-7.el8.noarch perl-Math-Complex-1.59-416.el8.noarch perl-PathTools-3.74-1.el8.x86_64 perl-Pod-Escapes-1:1.07-395.el8.noarch perl-Pod-Perldoc-3.28-396.el8.noarch perl-Pod-Simple-1:3.35-395.el8.noarch perl-Pod-Usage-4:1.69-395.el8.noarch perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-3.el8.x86_64 perl-Storable-1:3.11-3.el8.x86_64 perl-Term-ANSIColor-4.06-396.el8.noarch perl-Term-Cap-1.17-395.el8.noarch perl-Text-ParseWords-3.30-395.el8.noarch perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Time-Local-1:1.280-1.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-416.el8.x86_64 perl-libs-4:5.26.3-416.el8.x86_64 perl-macros-4:5.26.3-416.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 psmisc-23.1-3.el8.x86_64 Complete!

    Install php-mysqlnd package for PHP to MariaDB connectivity.

    [root@phpmyadmin-01 ~]# dnf install -y php-mysqlnd Last metadata expiration check: 0:00:23 ago on Wed 05 Feb 2020 06:01:30 PM PKT. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: php-mysqlnd x86_64 7.2.11-2.module_el8.1.0+209+03b9a8ff AppStream 190 k Installing dependencies: php-pdo x86_64 7.2.11-2.module_el8.1.0+209+03b9a8ff AppStream 122 k Transaction Summary ================================================================================ Install 2 Packages Total download size: 313 k Installed size: 781 k Downloading Packages: (1/2): php-pdo-7.2.11-2.module_el8.1.0+209+03b9 197 kB/s | 122 kB 00:00 (2/2): php-mysqlnd-7.2.11-2.module_el8.1.0+209+ 229 kB/s | 190 kB 00:00 -------------------------------------------------------------------------------- Total 274 kB/s | 313 kB 00:01 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : php-pdo-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 1/2 Installing : php-mysqlnd-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86 2/2 Running scriptlet: php-mysqlnd-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86 2/2 Verifying : php-mysqlnd-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86 1/2 Verifying : php-pdo-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 2/2 Installed: php-mysqlnd-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 php-pdo-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64 Complete!

    Enable and start MariaDB service.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# firewall-cmd --permanent --add-service=https success [root@phpmyadmin-01 ~]# firewall-cmd --reload success

    Open URL https://phpmyadmin-01.sysadminlabs.com in a client's 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.

    [root@phpmyadmin-01 ~]# cd /tmp [root@phpmyadmin-01 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.

    [root@phpmyadmin-01 tmp]# tar xvf phpMyAdmin-5.0.1-english.tar.gz --directory /var/www/html ... phpMyAdmin-5.0.1-english/vendor/williamdes/mariadb-mysql-kbs/test/index.js phpMyAdmin-5.0.1-english/vendor/williamdes/mariadb-mysql-kbs/test/parser.js phpMyAdmin-5.0.1-english/vendor/williamdes/mariadb-mysql-kbs/test/phpunit.xml phpMyAdmin-5.0.1-english/vendor/williamdes/mariadb-mysql-kbs/test/templates.js phpMyAdmin-5.0.1-english/version_check.php phpMyAdmin-5.0.1-english/view_create.php phpMyAdmin-5.0.1-english/view_operations.php phpMyAdmin-5.0.1-english/yarn.lock

    Rename extracted directory for better accessibility.

    [root@phpmyadmin-01 tmp]# cd [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# mysql -u root -p123 < /var/www/html/pma/sql/create_tables.sql

    Make a copy of sample configuration file.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# 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.

    [root@phpmyadmin-01 ~]# mkdir /var/www/html/pma/tmp

    Set apache user as the owner of pma directory.

    [root@phpmyadmin-01 ~]# chown -R apache:apache /var/www/html/pma/

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

    [root@phpmyadmin-01 ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/pma/tmp(/.*)?" [root@phpmyadmin-01 ~]# 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 client's 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.

    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