What is htpasswd?
At times during web development, we will need to prevent theÃÂ whole world from being able to access a particular website. That’s when Apache htpasswd comes into the picture. htpasswd is usually used together with htaccess.
Tutorial
This tutorial will teach you how to create a htpasswd file using command line.
Creating a htpasswd for the first time
htpasswd -c /<PATH_TO_YOUR_HTPASSWD_FILE>/.htpasswd <USERNAME>
Example
htpasswd -c /var/www/yourdomain.com/.htpasswd themerv
Appending new user to existing htpasswd file
htpasswd /<PATH_TO_YOUR_HTPASSWD_FILE>/.htpasswd <USERNAME>
Example
htpasswd -c /var/www/yourdomain.com/.htpasswd themerv
Using htpasswdÃÂ in htaccess
AuthName "Restricted Area" AuthType Basic AuthUserFile /var/www/yourdomain.com/.htpasswd require valid-user
That’s it you are done!
0 Comments