To Secure the Apache Virtualhost (or) a particular document root /directory. We can use this Basic Auth mechanism.
When the user is trying to access the resource from the directory. User will be prompted for Authentication.
Create a Password file with username and password entry using htpasswd tool. Available at apache bin directory.
This is how the users file looks like by default the password entered will be encrypted using MD5 algorithm
Make configuration changes in httpd.conf file.
Under the Directory module that you want to apply BasicAuth secuirty
Add the below lines
AuthType Basic AuthName sarasoftaccess AuthUserFile bin/users Require valid-user DirectoryIndex index.html Allow from all
This is how our configuration looks like
Here we are enabling security for both ROOT directory and Our Site's Document Root.
Restart the Web server and Test it using the URL
Now you will be prompted for the password.
When you enter the correct password that you have saved at step1. You will be able to see the page.