[APACHE] Password Protect a Directory with htaccess

If you like to password protect a directory on your web server, just create a .htaccess file into such a directory and put the following code:

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /path/directory/protect/.htpasswd
require valid-user

Then, generate the corresponding .htpasswd file by executing the following command:

/path/directory/protect$ htpasswd -c .htpasswd admin
New password:
Re-type new password:
Adding password for user admin

Reload your web directory and enter the credentials you’ve just chosen.