.htpasswd tutorial

Apache offers you to protect a folder and its subdirectories with .htaccess files. Learn how to protect your data in only two quick steps!

1. Create an .htpasswd file

Your .htpasswd file will contain the usernames and crypted password of the users who will be allowed in the directory you want to protect; htpasswd files typically look like this:


…where the part before the semicolon represents the username, and the right part is the encrypted password.

How to generate an htpasswd file ? Just follow these two easy steps:

  1. use this online htpassword generator, type the users you want to add and copy the generated text
  2. paste the text in a file named .htpasswd

2. Configure the .htaccess

Create a file named .htaccess at the root of the folder you want to protect, if it does not already exists. Paste this few lines in the file, then save it:

AuthName "Type a custom text here" 
AuthType Basic 
AuthUserFile /full/path/to/the/.htpasswd 
AuthGroupFile /dev/null 
require valid-user

You will have to edit the location of your .htpasswd file (/full/path/to/the/.htpasswd) for this to work properly.

Leave a Comment

Warning: Unknown: open(/var/lib/php5/sessions/sess_gid78rbv7hrb0dekcei3qtkt42, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php5/sessions) in Unknown on line 0