How to setup apache authentication

This post was written by Mahi-Bhat on January 8, 2013
Posted Under: Apache,Online Groups,OS Admin,PHP

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
http://httpd.apache.org/docs/2.2/howto/auth.html

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.

Add a Comment

required, use real name
required, will not be published
optional, your blog address

Previose Post: