Password protect directory – apache configurations

A usual scenario encountered by every web server is administrator is to password protect specific directory and all it’s resources. We need to add some lines in the configuration file where our web server / virtual host is defined. This is how we do it:

Creating the password file: (the system will ask you to enter the password which will be saved in encrypted format)

sudo htpasswd -c [filename] [username]

Apache BASIC HTTP Authentication using the created password file

 <Directory "[path to your directory]">
AuthUserFile [the path to the password file]
AuthType Basic
AuthName "RESTRICTED ACCESS"
Require valid-user
</Directory>

Majd Arbash

...

Leave a Reply