Posts Tagged ‘Password Protect’

How To Password Protect Directory Access Via Apache (HTTP)

I ran into a problem today, my team member asked me to password protect a directory in such a way that when someone access it via Web URL, it should first ask for password. Once user is validated then it should lead him/her to the actual web page.

Guess what is the most easy way to do it, I followed the following method and it worked perfectly. Since Apache is the web server and usually it is handling hundreds of websites on a single server so it is not a wise way to make changes in its configuration file often. We will achieve it via .htaccess.

Now go into the directory in which you wish to apply this restriction and create a .htaccess file (off-course if this does not exist already) and add the following lines with necessary modifications ( The only modification will be that you will need to change the path of the root directory of your applicaton).

AuthType Basic

AuthName “Admin”

AuthUserFile “/var/www/html/MYAPP/passwd”

require valid-user

Now create a file with name passwd at /var/www/html/MYAPP/ path and add the username and password in the following formate:

admin:K1/BaQTbqe0Eo

where admin is the username and the encrypted value after: is the password.

Restart apache service and you will be seeing the login prompt appearing on application launch.