phpMyAdmin is a best open source, free and web interface based database management tool for managing MySQL and MariaDB. You can manage MySQL databases, user accounts and privileges, import and export data and much more using phpmyadmin interface. This guide will help you to install phpMyAdmin with Apache on CentOS 7.
- Logged in on CentOS server as non-root user account with sudo privileges.
- Make sure that LAMP (Linux, Apache, MySQL and PHP) stack is installed on your CentOS system.
It’s recommend to access your phpMyAdmin installation over HTTPS connections to prevent from unecessary attacks. If your domain is not secure with an SSL/TLS certificate, you can follow this guide to Secure Apache with Let’s Encrypt on CentOS.
Installing phpMyAdmin on CentOS
phpMyAdmin package is not available on CentOS 7 core repositories. So we will install it from EPEL repository. To start installation you need to enable EPEL repository first by below command:
sudo yum install epel-release
Once EPEL repository enabled you can install the phpMyAdmin and it’s dependencies with the below command:
sudo yum install phpmyadmin
At the time of phpMyAdmin installation, created a Apache configuration file automatically. By default, all connections are denied except localhost so you will need to edit config file and add specific IP Addresses.
Open the phpMyAdmin config file by below command:
sudo nano /etc/httpd/conf.d/phpMyAdmin.conf
Now replace the Require ip 127.0.0.1 with Require ip YOUR_IP_ADDRESS. Where your ip address is your connections ip address. Following is the example after replace:
# Apache 2.4
Require ip 192.168.43.125
Require ip ::1
Save and close file.
Next, you need to restart Apache by typing:
sudo systemctl restart httpd
Create MySQL User and Set Privileges
You can create a separate mysql user for access from phpMyAdmin web interface. Login to mysql by below command:
Now, execute below commands to create a new administrative user with strong password and grant appropriate permissions:
mysql> CREATE USER 'newadmin'@'localhost' IDENTIFIED BY 'STRONG-PASSWORD';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'newadmin'@'localhost' WITH GRANT OPTION;
Exit MySQL shell by typing:
You can access the phpMyAdmin interface by open web browser and type your server’s public IP address or domain name followed by /phpmyadmin:
Log in to the interface with the administrative username and password which you created on previous step and hit on Go button.
When you log in, you’ll see the phpMyAdmin user interface, which will look something like this:
You can add one more security layer to your phpMyAdmin web interface by setting up a basic authentication. We will create password protected directory.
At First, we will create a password file with user using the
htpasswd tool that comes with the Apache package. We will store the
.htpasswd file in
sudo htpasswd -c /etc/phpmyadmin/.htpasswd newadmin
newadmin is administrative username which we created for access phpMyAdmin interface. You can choose any user name of your choice. Once you execute above command it will prompt you to enter password and confirm password as below:
Re-type new password:
Adding password for user newadmin
Now we will configure Apache to password protect the phpMyAdmin directory and use the
.htpasswd file. To do it open
phpmyadmin.conf by typing :
sudo nano /etc/httpd/conf.d/phpmyadmin.conf
Make changes as following:
Options +FollowSymLinks +Multiviews +Indexes # change this line
# Add new line start
AuthName "Authentication Required"
# Add new line end
After that, Save and close the file. To take effect restart the Apache service by type:
sudo systemctl restart httpd
Now, when you access your phpMyAdmin subdirectory, you will be prompt for the additional account name and password that you just configured:
Once you will enter basic authentication details then only you will be taken to the phpMyAdmin login page where you need to enter your MySQL administrative user login credentials.
By this tutorial, finally you have successfully installed phpMyAdmin with Apache on CentOS 7 system. If you have any questions or suggestions feel free to leave a comment below.