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
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/)
Paste the following lines in this file
AuthName “Restricted Area”
AuthUserFile /etc/httpd/conf/.htpasswd (path of htpasswd file)
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)
Allow from all
7. Restart the Apache web server. Execute the command below
Service httpd restart