Protecting a directory in Apache
Monday 19, December 2011

Sometimes it's very useful to protect a web directory with user/password. Apache web server offers us a simple method to do that based on HTTP basic authentication. We need to create a specific file called .htpasswd, then our conf. file should be changed for adding the protection. Let's do it:

$ htpasswd -c .htpasswd myuser

The previous command will create a new file called .htpasswd. This file should be located inside the directory which will be protected. Then we need to change our Apache's conf. file adding these lines:

<Location /mydirectory>
    AuthUserFile /home/myuser/mydirectory/.htpasswd
    AuthName "Protected area"
    AuthType Basic
    require valid-user
</Location>

When a user access to protected directory Apache will display a dialog box asking for user/passwd.

tags: Apache

Tags

Buy me a coffee!! Coffee cup

Advertisment