Techrider

RSS Feed URL: https://techrideradmin.blogspot.com/feeds/posts/default?alt=rss
Category: Science & Education | Total Views: 28

Latest entries from this feed

How to configure Basic Authentication with Apache using .htaccess on CentOS 7 server step by step guide

Posted on 7 January 2019 | 6:06 pm by



In this article we learn how to configure basic authentication with apache using .htaccess on centos server.

Apache is most popular web server all over the world. To enhance the security of apache by configuring  website with password authentication which is prevent malicious users from accessing the website.

Allow .htaccess authentication on apache

By default .htaccess is not enable on apache configuration file. We need to configure it .To configure it we need to go http default configuration file and search “<Directory "/var/www/html">section and under this section we need to change the From AllowOverride none to AllowOverride AuthConfig.

Create password file using htpasswd on apache

We need to create a hidden htpasswd file which is used to store the credential of user which is necessary to login the website. We are creating this hidden file under “/etc/httpd” directory.

To create the .htpasswd file we need to execute the below command.

#htpasswd -c /etc/httpd/.htpasswd testuser

After that put the password and confirm it ,it will stored into the hidden file.
The content of this file as below.

[root@localhost ~]# cat /etc/httpd/.htpasswd
testuser:$apr1$GQ7aRO.O$NCFWjQEqLUkUfQN7JwdGP1

Now we need to change the permission and ownership of the hidden file to read it by apache user.To do this we execute the below command.

#chown apache:apache /etc/httpd/.htpasswd
#chmod 660 /etc/httpd/.htpasswd

Now we create .htaccess file inside the web directory which is “/var/www/html” and add these below lines inside the files to configure password authentication on apache.

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user

After that we need to restart the apache service using the below command.

#systemctl restart httpd

After that when we are using the web url through browser we will get the authentication promt as below.
How to configure Basic Authentication with Apache using .htaccess on CentOS 7 server step by step guide
How to configure Basic Authentication with Apache using .htaccess on CentOS 7 server step by step guide

That's all.If this article is helpful please share it!!!






Related products

PILLS FRONT BRAKE PADS PADS BRAKE FRONT TECHRIDER PIAGGIO SPHERE 50

$36.75
End Date: Monday Feb-11-2019 17:49:34 PST
Buy It Now for only: $36.75
Buy It Now | Add to watch list

Women’s New Balance W560LG6 TechRider Running Athletic Shoes size 11

$29.99
End Date: Saturday Feb-16-2019 11:20:54 PST
Buy It Now for only: $29.99
Buy It Now | Add to watch list