Install and secure phpMyAdmin on Apache CentOS 7

phpMyAdmin is an open source PHP-based tool for managing MySQL and MariaDB servers via a web based interface.

PhpMyAdmin allows you to interact with MySQL databases, manage user accounts and privileges, run SQL statements, import and export data in various data formats and much more.

In this tutorial, we will cover the steps required to install and secure phpMyAdmin using Apache on CentOS 7.

precondition

Make sure you meet the following prerequisites before continuing with this tutorial:

  • LAMP (Linux, Apache, MySQL, and PHP) is installed on CentOS servers.
  • Log in as a user with sudo privileges.

Install phpMyAdmin

To install phpMyAdmin on CentOS 7, follow these steps:

  1. PhpMyAdmin is not available in the CentOS 7 base repositories. To install phpMyAdmin we need to enable the EPEL repository first:
    sudo yum install epel-release
  2. Once the EPEL repository is enabled, we can install phpMyAdmin and all its dependencies with the following command:
    sudo yum install phpmyadmin

Configure and secure phpMyAdmin

Apache configuration files for phpMyAdmin are created automatically during installation. By default, all connections except for those from localhost will be rejected.

Since we will be accessing phpMyAdmin from the internet, we need to modify the configuration file and specify the allowed IP addresses.

Open the phpMyAdmin Apache configuration file:

sudo nano /etc/httpd/conf.d/phpMyAdmin.conf

Change the two lines that read Require ip 127.0.0.1 With your IP address connected. If you do not know your home IP, open Google in a web browser and type what is my ip.

# Apache 2.4
<RequireAny>
    #Require all granted  #Untuk izinkan akses dari manapun 
    Require ip 192.168.42.57 #opsi tambahan
    Require ip ::1
</RequireAny>

Close and save the file.

If you want to be able to access your phpMyAdmin installation from anywhere on the Internet then add or remove the hashtag (#) Before Require all granted Before the streak Require ip.

For an extra layer of security, we will password protect phpMyAdmin directory by setting up basic authentication.

Start creating a new authentication file using the tool htpasswd. We’ll save the file .htpasswd In the manual /etc/phpMyAdmin:

sudo htpasswd -c /etc/phpMyAdmin/.htpasswd admin

In this example we are creating a username admin. You can choose any username you want.

The above command will require you to enter and confirm the user’s password.

New password: 
Re-type new password: 
Adding password for user admin

Then, if you need to add additional users, use the same command without tags -c:

sudo htpasswd /etc/phpMyAdmin/.htpasswd adminlain

The next step is to configure Apache to be able to password-protect the phpMyAdmin directory and use it .htpasswd . To do this, open the file phpMyAdmin.conf Created automatically while installing phpMyAdmin:

sudo nano /etc/httpd/conf.d/phpMyAdmin.conf

And enter the following lines highlighted in yellow:

<Directory /usr/share/phpMyAdmin/>
    AddDefaultCharset UTF-8

    Options  +FollowSymLinks +Multiviews +Indexes
    AllowOverride None
    AuthType basic
    AuthName "Authentication Required"
    AuthUserFile /etc/phpMyAdmin/.htpasswd
    Require valid-user

   <IfModule mod_authz_core.c>
   ...

Save the file and restart the Apache service for the changes to take effect:

sudo systemctl restart httpd

For security reasons, it is recommended that you change the alias /phpmyadmin To be another unique and safer name.

Upon accessing phpMyAdmin, you will be prompted to enter the user login credentials you previously created:

https://domain_atau_alamat_ip/phpmyadmin

After entering basic authentication, you will be taken to the phpMyAdmin login page where you will need to enter the MySQL administrative user login credentials.

Access to phpMyAdmin

To access the phpMyAdmin interface, open a browser and type in the server’s domain name or public IP address followed by /phpmyadmin:

https://your_domain_or_ip_address/phpmyadmin

Phpmyadmin basic authentication

Enter the administrative user login credentials you created earlier and click on it Go.

Enter phpmyadmin

Once logged in, you will see the phpMyAdmin dashboard, which will look like this:

phpmyadmin dasboard

Conclusion

Congratulations, you have successfully installed phpMyAdmin on your CentOS 7 server. Now you can start creating MySQL databases, users and tables, and perform various MySQL queries and operations.

.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *