Sunday, August 28, 2011

Adding htpasswd to Apache

If we want to protect certain directories in Apache with a password then we need to edit the file


STEP1: Copy paste these lines in there, base is the folder which I am trying to protect.


STEP2: Now restart apache.

root@test:/etc/apache2# /etc/init.d/apache2 restart
 * Restarting web server apache2   .... Waiting [ OK ]

STEP3: Now we need to create a file called as .htaccess under the folder we want to protect and enter these lines in there.

AuthUserFile /etc/apache2/base_passwords
AuthName "Authorization Required"
AuthType Basic
require valid-user

Here base_passwords is the file which will store the passwords.

STEP4:To create base_passwords follow the steps give below.

root@test:/etc/apache2# htpasswd -c base_passwords bala
New password:
Re-type new password:
Adding password for user bala
root@test:/etc/apache2# cat base_passwords

Wola now when we type the url http://localhost/base we will get an authorization prompt.

No comments:

Post a Comment