Secure PhpMyAdmin Login on Ubuntu 22.04


It is very important to secure phpmyadmin login access, why any hacker or attacker can damage your database by attacking phpmyadmin. Through this tutorial, we will show you two simple methods to secure PHPMyAdmin login access on ubuntu 22.04 apache 2 web server.

There are two solutions to secure PHPMyAdmin login access in Ubuntu 22.04 Apache 2 server.

  • Solution 1 – Secure PhpMyAdmin Login Page By Changing Login URL
  • Solution 2 – Secure PHPMyAdmin Access Using htpasswd

Solution 1 – Secure PhpMyAdmin Login Page By Changing Login URL

In Ubuntu, default phpmyadmin login URL can be located at Apache configuration that names apache.conf. So, you can use the 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 with 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 Using htpasswd

Create an .htpasswd file to store the username and encrypted password. Choose a secure location for this file; for example, we’ll create it in the phpMyAdmin directory:

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

Replace your_username with the desired username. You’ll be prompted to enter and confirm a password.

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


Through this tutorial, we have learned how to secure phpmyadmin on ubuntu 22.04 system.


Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Jassweb, Rai Chak, Punjab, India. 143518