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:
- Open your shell and go to your directory that you want to password protected
- 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
- You will prompt to fill the password
- Make a .htaccess file or edit it if it is already exists
- Add these line:
AuthUserFile /path/to/your/directory/.htpasswd AuthType Basic AuthName "Your Message Here" Require valid-user
- Save .htaccess file.
- That’s it, now you have a password protected directory.