Friday 3 August 2012

Apache basic authentication

To create a password file, in cmd prompt go to the bin dir where htpasswd.exe is present and type the below cmd

htpasswd -c test test

third parameter is name of the file where credentials are stored.
fourth parameter is the username. After executing this command, it prompts for password and a file named test will be created in bin dir.
The below config is placed in the conf file
<Directory "C:/Program Files/Apache Group/Apache2/htdocs/test" > // file path where authentication is needed
AuthType Basic
AuthName "Private Documentation Repository" // can be anything
AuthUserFile "C:/Program Files/Apache Group/Apache2/bin/test"  //path to file containing username and password

</Directory>
Restart the apache and restart the browser and try hitting , http://localhost/test. It asks for credentials.
Reference:
http://httpd.apache.org/docs/2.0/howto/auth.html
http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html

No comments:

Post a Comment