• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install phpMyAdmin with Apache on CentOS 7

Written by Admin, Updated On May 7, 2019
apache, centos, mariadb, mysql, php, phpmyadmin
How to Install phpMyAdmin with Apache on CentOS 7

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.

Prerequisites#

  • 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

Configure 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
<RequireAny>
    Require ip 192.168.43.125
    Require ip ::1
</RequireAny>

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:

sudo mysql

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:

exit;

Accessing phpMyAdmin#

You can access the phpMyAdmin interface by open web browser and type your server’s public IP address or domain name followed by /phpmyadmin:

https://ip_address_or_your_domain/phpmyadmin

Log in to the interface with the administrative username and password which you created on previous step and hit on Go button.

phpMyAdmin Login page

When you log in, you’ll see the phpMyAdmin user interface, which will look something like this:

dashboard phpmyadmin centos

Securing phpMyAdmin#

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 /etc/phpmyadmin directory:

sudo htpasswd -c /etc/phpmyadmin/.htpasswd newadmin

Here, 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:

New password:
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:

<Directory /usr/share/phpmyadmin>
    Options  +FollowSymLinks +Multiviews +Indexes  # change this line
    DirectoryIndex index.php

    # Add new line start
    AllowOverride None
    AuthType basic
    AuthName "Authentication Required"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user
    # 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:

https://ip_address_or_your_domain/phpmyadmin
login box

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.

Conclusion#

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.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article Secure Nginx with Let’s Encrypt on Debian 9
Next Article   How to Install phpMyAdmin with Nginx on CentOS 7

Related Posts

  • How to Install WordPress with Nginx on Debian 11

    How to Install WordPress with Nginx on Debian 11

    March 22, 2023
  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook