Thursday, December 24, 2009

Apache basic authentication:

Say you are using apache web server (tested on version 2.2) to publish a website hosted under a given directory (say /home/eortega/public_html/limesurvey_server7/) and you want to protect access to it by using basic authentication (i.e. a username and password must be provided by the client browser to access the contents, and the user names and passwords are stored on a text file). You need to do the following:

1. Create a .htaccess file on the directory, namely:

/home/eortega/public_html/limesurvey_server7/.htaccess

with the following content:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /home/eortega/public_html/limesurvey_server7/.htpasswd
Require user eortega

2. Create a password file as specified in the .htaccess file. In this example, it is /home/eortega/public_html/limesurvey_server7/.htpasswd
To create this file, you must use apache´s htpasswd utility as follows:

htpasswd -c /home/eortega/public_html/limesurvey_server7/.htpasswd eortega

This means "create .htpasswd file under /home/eortega/public_html/limesurvey_server7/ and add password for user eortega" (password is prompted on the console).

I hope this helps.

oh, yeah, and merry christmas.


No comments: