Apache: Password Protecting Directories

I always forget how to add simple password protection with Apache 2 so here's a reminder to myself.

1. Add directive: "AllowOverride All" (no quotes) into the protected <Directory> configuration entry. Depending on your setup, the <Directory> entry may be under /etc/apache2/apache2.conf or /etc/apache2/sites-available.default. For example:

DocumentRoot /home/omerk/wwwroot
<Directory />
   Options FollowSymLinks
   AllowOverride All
   SetOutputFilter Deflate
</Directory>

2. Open a shell prompt and cd into the protected directory

3. Run: htpasswd -c .htpassword yourname
Enter your password when requested.

4. Also in the protected directory, create .htaccess file with the following content:

AuthType Basic
AuthName "restricted area"
AuthUserFile /{full path from the root of the drive}/.htpassword
require valid-user

5. Restart apache with: sudo /etc/init.d/apache2 restart

That should be it.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.