Introduction

This guide is for users who have already configured a CentOS server and installed the Apache HTTP services, MySQL database management system, and the PHP programming language.

The database utility, phpMyAdmin, is used for managing MySQL databases through a graphical web-based interface. It can be configured to manage a local database (on the same system), or a remote database (over a network). It replaces the awkward default command-line interface for MySQL management.

This article will help you install phpMyAdmin and configure basic security in Centos 7.

Prerequisites

    • LAMP (Linux, Apache, MySQL, PHP) stack installed on the server.
      • Linux is fulfilled with CentOS 7.
      • Apache is software for transmitting information over the internet.
      • MySQL is a data base application that we are managing with phpMyAdmin.
      • PHP is a programming language for interpreting phpMyAdmin's commands.
    • Access to a user account with root privileges (ability to use the sudo command).

Tools/Software

  • The CentOS 7 operating system.  CentOS is a Red Hat derivative and is designed to be stable, manageable, and scalable.  More information can be found here.
  • The YUM update manager, which is a default component of CentOS 7.
  • A command prompt with root access.  You can open a command prompt by clicking Menu > Applications > Utilities > Terminal.
  • A text editor. Vim, which is included with most Linux installations, is fine. You may substitute Vim for a text editor of your choice.

Installation Procedure

Step 1: Getting Access To phpMyAdmin in Centos 7

(If you’ve already installed EPEL, you can skip this step.)

CentOS 7 does not have access to phpMyAdmin in its default software repository. You’ll need to get access to the EPEL repository – the Extra Packages for Enterprise Linux.  Type the following at the command prompt, then hit enter:

sudo yum install -y epel-release

Once that operation finishes, it’s a good idea to refresh and update the EPEL repository:

sudo yum –y update

Step 2: Installing phpMyAdmin

Installing the software is fairly straightforward.  At a command prompt, enter the following:

sudo yum -y install phpmyadmin

Once the system executes the command, myPhpAdmin is installed and ready to launch.  You can open the application and start using it right away by opening the following address in a web browser:

https://IP_OR_DOMAIN/phpmyadmin

NOTE

Fill in the location of your own public server information in place of “IP_OR_DOMAIN.” You’ll need to collect this information from your particular server configuration. It’ll usually be your domain name or the IP address of your server.

Step 3: Configuring phpMyAdmin

Your new software installation includes a default Apache configuration file. You’ll want to make some changes to that configuration to prevent unauthorized access. Here are two common ways of restricting access to unauthorized users.

Option A: Restrict IP Addresses

This method can be used to grant remote access to a single workstation. By default, phpMyAdmin is configured so that the server it’s installed on has access. This change lets you allow or restrict access to specific IP addresses of different or additional computers.

The file is located at /etc/httpd/conf.d/phpMyAdmin.conf. Type the following at your command prompt:

sudo vim /etc/phpMyAdmin/config.inc.php

Inside the config file, you should see four (4) lines that refer to “Require IP” or “Allow IP.”  By default, they should be set to 127.0.0.1, which is the IP address referring to the system you are working on. To allow other systems to access this phpMyAdmin application, add (or change) these numbers to the IP address of the computer you want to grant access to.

Once you’ve made the changes, save the file.

NOTE

You can use https://whatismyipaddress.com/ or https://www.whatismyip.com/ to find the IP address of the system you’re working on.

Option B: Change the Alias

Open phpMyAdmin.conf using a text editor:

sudo vim /etc/phpMyAdmin/config.inc.php

Near the top, you should see two lines:

Alias /phpMyAdmin /usr/share/phpMyAdmin

Alias /phpmyadmin /usr/share/phpMyAdmin

“Alias” is how the internet will see your phpMyAdmin configuration. Since the default configuration is an easy target for bots and hackers, consider changing the alias setting. Just put a ‘#’ sign before the existing entries so the program sees them as comments, rather than instructions. Then add your own line:

Alias /MySecretLogin /usr/share/phpMyAdmin

NOTE

You can replace “MySecretLogin” with any alias you like.

Now, when you go to your login screen, you’ll have to type https://IP_OR_DOMAIN/MySecretLogin (or whatever you choose) to gain access.

Once you’re finished making changes, save the file.

Step 4: Restart Apache

Regardless of which configuration you use, you’ll need to restart the Apache service to see your changes:

sudo systemctl restart httpd.service

Conclusion

PhpMyAdmin is a widely-used application for managing databases. Hopefully, you found this guide on Installing and Securing PhpMyAdmin on Centos 7 useful.