When projects are in development stage or we may have some internal projects related to intra center and we do not intend to share/allow access to outside users, then how can we prevent this? This basic HTTP authentification can be done using .htaccess

step1: Decide the paths which you want to protect

- Path: /var/www/html/,
Path to .htaccess : /var/www/html/.htaccess,
Path to password file : /var/www/my_password_file,


step2: Create a .htaccess file

AuthType Basic
AuthName “Authentification required”
AuthUserFile /var/www/my_password_file
Require user admin_user


step3: create a password file

htpasswd -cb /var/www/html/my_password_file admin_user password

Explaination:

In step1,

  • - /var/www/html/ is a path which has to be protected from outside users,
  • - and so we have to keep .htaccess file right in that directory level,
  • - path to the Password file ‘my_password_file’ is /var/www/my_password_file,

In step2,

  • AuthType Basic - Suggests that we are choosing the Basic authentification type.
  • AuthName “Authentification required” - prompts for user name password and with the pop up title ‘Authemtification required’.
  • AuthUserFile - Specifies the path to the password file.
  • Require user - We are mentioning which is the user name that should be used.

In step3,
using htpasswd we are creating the password file ‘my_password_file’ for user ‘admin_user’ and we are specifying password as ‘password’

Reference Links:
http://httpd.apache.org/docs/1.3/programs/htpasswd.html

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Simpy
  • StumbleUpon
  • Technorati
  • YahooMyWeb