Password Protect Folder / Directory with htaccess and htpasswd on Apache and Linux / Unix

Step 1 - Create .htaccess file in folder you want to protect, copy the code and paste the code below, and then set server path to the file

AuthUserFile /path/to/.htpasswd
AuthName "Restricted Area"
AuthType Basic
Require valid-user

Step 2 - Open Terminal, go to the directory you want to protect, and enter the following (changing the username to whatever you want). Enter the password upon prompting.

htpasswd -c .htpasswd username

source

Leave a Reply