How to just:
Categories: Technical | design | Other | Food | All

How to password protect an apache directory

Description:

You want to password protect a website? directory on a website? This is how.


So you want to password protect a directory on a website, do you?
You need to create a file called ".htaccess", and you want to create this in the directory that you're protecting. We'll use howtojust.com as an example for this. Say that I have a directory on howtojust called "secrets", which is located at /var/www/howtojust/htdocs/secrets/ This is what I would do.
 $ cd /var/www/howtojust/secrets
 $ nano .htaccess
(vim works better!)
.htaccess should look like this:
 AuthName "Secrets are in here!"
 AuthType Basic
 AuthUserFile /var/www/howtojust/htdocs/secrets/.htpasswd
 AuthGroupFile /var/www/howtojust/htdocs/secrets/.htgroup
 require group people_i_trust

 Options +ExecCGI
substitute "howtojust" and "secrets" with whatever the values for your website are.
You'll also need a file called ".htgroup"
 $ nano .htgroup

 people_i_trust: gandalf
That's it. Just the name of a group, followed by a : followed by the username you want them to have
Now you need a file called .htpasswd do it like this:
 $ htpasswd .htpasswd gandalf
It will prompt you for the password, then you'll confirm it...and that is it! Try opening your directory now and you'll be prompted for a password. If you followed exactly what I did, you'd type "gandalf" and then whatever password you put in after htpasswd

good luck!

Link to this



Be sure to check out our other project, Thingist - Things you love Looking for other Technical articles?
Here is another random article from this category:

How to download flash videos from the internet (For my coolest friend ever)

How to download flash videos from the internet. How to download flip videos, and youtube videos, and probably every other kind of video you want. Hooray!

Read More
Be sure to check out our other project, Thingist - Things you love