In my previous article about Creating or Updating Users in htpasswd File, we saw how to create, update and remove user from htpasswd file. In this article, we will see how we can configure this file in Apache web server so that users will be prompts to provide credentials for accessing the web sites hosted with Apache web server.
Follow my previous article and setup the users. Next, go to httpd and open the file which has virtual host configurations for your web site. Update the virtual host entry, it should looks something like this:
Note that AuthType, AuthName, AuthUserFile and Require are important. Make sure to remove “Require all granted” from the virtual host entry (if you have it already). Otherwise, your website will be accessible without any authentication.
That’s it. Restart you Apache Web Server and now you will be prompted to provide credentials when you try to access the web site.