Apache web server – password protect your website / directory

You are developing a new site and wish to keep it secret till your new site is ready for launch?
You got personal photos, confidential documents, project codes uploaded to your web server for future reference or download and you want to give access only to certain people?

One of the solutions is to password protect your directory where the restricted stuffs were stored.

“How to password protect the directory or entire website?”

Requirements:
– Hosted on apache server
– Apache module mod_access is enabled.

Step 1
Create password file “.htpasswd”. In the folder / site root you wish to password protect, create a .htpasswd file. The password file stores your valid users’ username and password.

Step 2 Use online passwd generator to create user’s username and password entry for htpasswd. http://www.htaccesstools.com/htpasswd-generator/ Copy and paste the entries into “.htpasswd”.

Example of an .htpasswd file

denny:$apr1$7APPNnCz$M./pcs91u296uBP0VAD4J1

Step 3
In the same folder, create/edit .htaccess to include the following codes.

AuthUserFile /absolute/path/to/.htpasswd
AuthType Basic
AuthName "Prompt Title"
Require valid-user

Note: Relative path to .htpasswd will not work.

Final Step
Launch your browser, navigate to the password protected folder, you will receive a authentication challenge if nothing goes wrong.

=D That’s all.