How to password protect web directory (folder)
1. Create .htaccess file with the content below:
AuthUserFile /home/username/htdocs/.htpasswd
AuthName “Password Protected”
AuthType Basic
require valid-user
Of course in the AuthUserFile type in the location of the .htpasswd file (i.e. when you want to store that file, you’ll create it in next step)
2. Set password for the user(users) (-c option creates .htpasswd file)
If it is your first user’s password - use -c option
htpasswd -c .htpasswd username
type and confirm password
that’s all
(for other users you should ommit -c, because you not need to create .htpasswd file, simply write
htpasswd .htpasswd anotherusername
type and confirm password)