Tag Archives: htpasswd

How to create Password protected website on Apache in Centos 6

1. Create website and check if it is accessible via browser. Once confirmed that your website is working, proceed to step 2.

2. Create a htpasswd file in /etc/httpd/conf/
[root@mac1 conf]# htpasswd -c .htpasswd admin
New password:
Re-type new password:
Adding password for user admin

3. Set .htpasswd file permission 0644 so that it is accessed to Apache user and group of Apache server.
chmod 0644 .htpasswd

4. Now create .htaccess file in your document root where the website is placed (/var/www/html/)
#vim /var/www/html/.htaccess
Paste the following lines in this file
AuthType Basic
AuthName “Restricted Area”
AuthUserFile /etc/httpd/conf/.htpasswd                (path of htpasswd file)
require valid-user

5. Set permission 0644 to this file so that it is access to Apache user and group.
[root@mac1 conf]# chmod 0644 /var/www/html/.htaccess

6. Now open httpd.conf file and paste the following lines in your Virutal host
<Directory “/var/www/html”>                                  (path of your document root)
AllowOverride AuthConfig
Order allow,deny
Allow from all

7. Restart the Apache web server. Execute the command below
Service httpd restart