How to Secure PhpMyAdmin Apache Ubuntu 22.04

In this tutorial, i am going to show you two 2 ways to secure PHPMyAdmin login in ubuntu 22.04 apache 2 web server.

Because by default, phpmyadmin login url is located on http:///phpmyadmin. So, The main reason of change phpmyadmin login url in ubuntu apache server to prevent attackers attack.

How to Secure PhpMyAdmin Apache Ubuntu 22.04

Just follow the below given ways to secure PHPMyAdmin login access in ubuntu apache 2 server.

  • Solution 1 – Change PhpMyAdmin Login Page URL in Apache 2 Ubuntu
  • Solution 2 – Secure PHPMyAdmin Access in ubuntu apache 2

Solution 1 – Change PhpMyAdmin Login Page URL in Apache 2 Ubuntu

In ubuntu, default phpmyadmin login url can be located at apache configuration that name apache.conf.

So, you can use sudo nano /etc/phpmyadmin/apache.conf command to open apache.conf file:

sudo nano /etc/phpmyadmin/apache.conf

Then, you can add the following line with your phpmyadmin url:

Alias /my-phpmyadmin /usr/share/phpmyadmin

Note that, you can replace my-phpmyadmin to your own word.

Now you need to restart apache 2 web server. So type the following command on your ssh terminal to restart apache service:

sudo service apache2 restart

Solution 2 – Secure PHPMyAdmin Access in ubuntu

Now, you can add extra security layer for access phpmyadmin login in ubuntu apache 2 web server.

So, first of all, you need to create a password file with users using the htpasswd tool that comes with the Apache package. So open your ssh terminal and type the following command:

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

Note that, You can choose any username instance of myAdmin with above command.

After that, one prompt box appear with password and confirm password. So, you can add password and confirm password here.

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

Now, you need to configure Apache 2 to password protect the phpMyAdmin directory and use the .htpasswd file.

So, open your ssh terminal and type the below command to open the phpmyadmin.conf file.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Then add the following lines in phpmyadmin.conf file and save it:

Options  +FollowSymLinks +Multiviews +Indexes  # edit this line
DirectoryIndex index.php

AllowOverride None
AuthType basic
AuthName "Authentication Required"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Finally, restart apache web server by using the following command:

sudo service apache2 restart

Conclusion

In this tutorial, i have shown to you two 2 ways to secure PHPMyAdmin login in ubuntu 22.04 apache 2 web server.

More Tutorials

Leave a Comment