Basic HTTP Authentication is when a user is required to log in to access a directory. This isn't meant to be secure by any means, but it's useful for locking out a majority of users from accessing a folder (e.g. staging a website).
To start, you must add this into your .htaccess:
AuthUserFile "/var/www/full/path/to/your/folder/.htpasswd"
AuthName "Message to go on user's login screen"
AuthType Basic
Allow from all
Require valid-user
Options +Indexes
It's recommended to have the .htpasswd
outside of your public directory (if possible).
Next, generate an .htpasswd
. Run this command on your server's console:
htpasswd -bc /var/www/full/path/to/your/folder/.htpasswd username password
You can specify what username/password combination you'd like.
Done!