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

Conclusion

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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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