Archive for March, 2014

Password Authentication for Webpages in Apache on LInux Servers:

1. Go to the document root of the site.

[root@centos ~]# cd /var/www/html/myapp

myapp is the folder where all my application files located

2. Now create a .htaccess file

[root@centos ~]# vi .htaccess
Now add below info on it

AuthUserFile /var/www/html/myapp/.htpasswd
AuthName “Authorization Required”
AuthType Basic
require user USER_NAME

Note: Change the USER_NAME as you wish

3. Create a user for webpage authentication

[root@centos ~]# htpasswd -c /var/www/html/testfolder/.htpasswd USER_NAME

4. Open the apache configuration file add below lines to end of the file or to virtualhost configuration

###FOR myapp authentication ###

 <Directory “/var/www/html/myapp”>

 AllowOverride AuthConfig


[root@centos ~]# vi /etc/httpd/conf/httpd.conf

Save and quit the file

5.  Reload or restart apache services and browse the site. It asks for authentication.