Add Apache 2 Password Authentication to the directory

Since you already have phpMyAdmin installed, open its main configuration file and make the changes below.

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

Add the highlighted line below on the file:

Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride All
    </Directory>
</VirtualHost>

Save and close the file when you are finished. Restart Apache to implement your password policy:

sudo service apache2 restart

Next, create a .htaccess file by running the commands below:

sudo nano /usr/share/phpmyadmin/.htaccess

Then add the content below in the file and save:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Next, run the commands below to install Apache2 utility to create htpasswd

sudo apt-get install apache2-utils

Run the commands to create an account for richard.

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

You should be prompted to create a password.

Restart the web server to password protect all content in or below the directory with the .htaccess file:

sudo service apache2 restart

The next time you try to access the site, you should see a prompt for a username and password.

Now users should be authenticated twice to access e.g. phpMyAdmin.