The phpMyAdmin folder or admin (administration) folder should already have a log in form that forces people enter their valid username and password to access the dashboard. However, you may need a second level of protection to ensure your system is safe and secure.
Protected Web Directories or Password Protect module is always available in Control Panel supported by almost popular hosting provider. If you can’t find where is it or don’t know how to do it, let follow steps below. You need to have access to your hosting and familiar with secure shell command.
Steps to setup Protected Web Directories with .htaccess
1. Log in to your account via SSH and jump to the folder you want to protect
2. Create a file name called .htpasswd and grant access
This file will contain username which is granted access to this protected folder and encrypted password.
Type the command below:
[text] htpasswd -c .htpasswd user1[/text]
After press enter, you will be prompted to enter the password for user: user1 then re type the password to confirm. If the passwords are matched, a .htpasswd file will be created with content similar to:
[text] hoanhuynh:vfWdjKLO5bzAA[/text]
If you want to add more, simple re use the command above without -c:
[text] htpasswd -c .htpasswd user2[/text]
3. Create or modify the .htaccess file
You can use your favorite FTP client to create or upload a .htaccess file to the folder you want to protect with few lines below:
[text] AuthUserFile /enter/location/of/.htpasswdAuthGroupFile /dev/null
AuthName PleaseLogin
AuthType Basic
require user user1
[/text]
The content above will allow username user1 to access to the protected folder. And you need to update the location of the .htpasswd file we created on step 2.