How to Configure Website Using Htaccess with Apache in Linux

Step 1: Prerequisite

Step 2: Create Directory

Create a directory in /var/www/html/ (where DocumentRoot of apache is pointed).

# mkdir /var/www/html/testfolder
# cd /var/www/html/testfolder

Step 3: Create .htaccess File

Now create a .htaccess file using the touch command and insert the following lines in it:

# touch .htaccess
# vi .htaccess
AuthUserFile /var/www/html/testfolder/.htpasswd
AuthGroupFile /www.null
AuthName "Authorization Required"
AuthType Basic

require user USER_NAME

Set the password by executing the htpasswd command for htaccess

# htpasswd -c /var/www/html/testfolder/.htpasswd USER_NAME

Step 4: Configuration in Apache

Edit the /etc/httpd/conf/httpd.conf file and add the lines:

# vi /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/testfolder">
AllowOverride AuthConfig
</Directory>

Step 5: Restart Apache Server

In the end restart the httpd service:

# service httpd restart
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *