For few scenarios we need to protect our Drupal site accessing to everyone instead for a selected group of users. The http password will help us the Drupal site not to show up in Google search results. This will help to avoid the development site in search indexing. Also the user wants to access the site is able to access by using the HTTP username and password.
The Cpanel will allow to add http password protection directly inside the Cpanel itself. Inside the security option in the Cpanel we will get the options for adding the http protection.
For an apache server, it's very easy to add the http protection. Go to the folder where we need to add the.Httpasswd file as its it contain the username and password kept it outside the root folder
Inside the server use the below commands to
htpasswd -c .htpasswd username
After running the above command it will ask for the password we need to add to the Drupal site. Also, we need to retype the password it will be added inside the .httpasswd file. We can check the same from the below command.
vim .htpasswd
It will show the username along with the password in the below format
username:$apr1$zP7myWz8$24Y0om3/nvgOyGAAbyosy/
After adding the .htpasswd goto the .htacess file where we need to add a few lines of code. Below are the few line of code need to add inside the .htaccess file.
AuthUserFile //.htpasswd
AuthType Basic
AuthName "Restricted Access"
Require user username
Please provide the correct path to the .htpasswd file as its important the path need to be correct.