Configuring Apache with Authentication

Basic Authentication:

1. Create user database with htpasswd
htpasswd is a program which create user database. In this example we will create users in /etc/apache2/users

    $ htpasswd -c /etc/apache2/users test  ===========> Here test is username

2. Server side configuration: Here in httpd.conf or your virtual host configuration file between <Directory … >  </Directory> Give following settings 

In our example our DocumentRoot is /var/www/neelesh

<Directory /var/www/neelesh>
AllowOverride AuthConfig
…..
….
</Directory>

3. Create .htaccess file under /var/www/neelesh and put following entries into that

AuthName "restricted stuff"
AuthType Basic
AuthUserFile /etc/apache2/users
require valid-user

Neelesh Gurjar has written 122 articles

Leave a Reply