Sometimes you want to make an online application but only for private use or use by some people only. Or you just made an online application but still in testing phase in development, and don’t want to make the site go live yet. Or you want a web site or a directory to be protected for security reasons. Or other reasons that you can mention. But the point is you want a whole website or a directory to be password protected.
You can make a whole website or a directory password protected with Apache web server in Linux/Unix server.
These are the steps:
1. Open your shell and go to your directory that you want to password protect.
2. Make a .htpasswd file in that directory with this command:
htpasswd -c .htpasswd username
If you already have .htpasswd file you can add another user with this command:
htpasswd .htpasswd otheruser
3. You will be prompted to fill in the password.
4. Make a .htaccess file or edit it if it already exists.
5. Add these lines:
AuthUserFile /path/to/your/directory/.htpasswd
AuthType Basic
AuthName "Your Message Here"
Require valid-user
6. Save .htaccess file.
7. That’s it, now you have a password protected directory.
Please refer to Apache documentation for htpasswd and htaccess details.
