Password protecting an Apache Server

If you need to protect a web server so that a folder cannot be access without entering a password first.

First ensure that the option is turned on

vim /etc/apache2/sites-available/default

change

AllowOverride None

to

AllowOverride All

Now, create a .htaccess file

AuthUserFile /var/htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user

Instead of “valid-user”, you can enter the usernames you want.

Finally create a password file. For each user, replace “username”

htpasswd -c /var/htpasswd username

You will need to double enter the password.

Finally, restart apache

service apache2 restart

done

Leave a Reply

Your email address will not be published. Required fields are marked *