How to Protect a Directory with Password Using .htaccess in Apache2

Create a new .htaccess file

cd /var/www/mywebsite.com/secret
touch .htaccess

Insert this value in the .htaccess file

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /home/mike/.htpasswd
Require valid-user

Create a new password file

htpasswd -c /home/mike/.htpasswd mike

Lastly, restart apache2

service apache2 restart

comments powered by Disqus