[TUTORIAL] Password Protected Directory In Apache Web Server

Sometimes you want to make an online application but only for private use or use by some people only. Or you just made an online application but still in testing phase in development, and don’t want to make the site go live yet. Or you want a web site or a directory to be protected for security reasons. Or other reasons that you can mention. But the point is you want a whole website or a directory to be password protected.

You can make a whole website or a directory password protected with apache web serverĀ  in linux/unix server.

These are the steps:

  1. Open your shell and go to your directory that you want to password protected
  2. Make a .htpasswd file in that directory with this command:
    htpasswd -c .htpasswd username

    If you already have .htpasswd file you can add another user with this command:

    htpasswd .htpasswd otheruser
  3. You will prompt to fill the password
  4. Make a .htaccess file or edit it if it is already exists
  5. Add these line:
    AuthUserFile /path/to/your/directory/.htpasswd
    AuthType Basic
    AuthName "Your Message Here"
    Require valid-user
  6. Save .htaccess file.
  7. That’s it, now you have a password protected directory.

Please refer to apache documentation for htpasswd and htaccess details.


  1. afiszone says:

    Gue baru aja kemarin di ajarin di kuliah .. !! hehehe …

  2. afiszone says:

    Gue baru aja kemarin di ajarin di kuliah .. !! hehehe …

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.