How to setup apache authentication

1. Open/create .htaccess file in your directory (the directory you wish to protect)

2. Add below given block of rules

AuthType Basic
AuthName “Demo”
AuthUserFile /usr/local/apache/passwd/http_passwords
Require user valid-user

3. At the command prompt type and press enter

htpasswd -c /usr/local/apache/passwd/http_passwords demouser

It will ask you for the password, and then ask you to type it again to confirm it. The contents of the http_passwords will be of the form

demouser:<encrypted password string>

For detailed information please visit below given URL

If you have already assigned the AuthName ‘Demo’ to some other directory in the same domain then it will prompt for user name and password multiple times or every time you click on any links or make any AJAX calls. To avoid this, please be sure that this setting is unique and also make sure that there are no other references/links to any other protected directory from the same page.