How to protect a URL with a Basic Authentication password
First, create a .htaccess
file in the directory you wish to protect with a password:
This will typically be the document root of your application /home/myaccount/apps/application/.
AuthUserFile /home/myaccount/.htpasswd
AuthName "Title_of_the_login screen"
AuthType Basic
Require valid-user
Here the path to the AuthUserFile
is important, because in this file we are going to store the different users and their encrypted passwords.
At AuthUserFile
, make sure you enter the absolute path to your .htpasswd
file.
You can then create the first user using the htpasswd
command via SSH:
htpasswd -b -c /home/myaccount/.htpasswd username
When adding additional users later, simply leave out the -c
flag (create new file)
htpasswd -b /home/myaccount/.htpasswd username