Setup password authentication for Apache2

From PheonixSolutions
Jump to navigation Jump to search

Setup password authentication for Apache2 in Centos

1. Login to the server using ssh.

2. To create the authentication of the apache2 it is necessary to have the apache2 on server. Check whether the server has already installed apache2 and check the version here we have already installed apache2 so we just updated the apache2 service.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_d1d3bf31e983401585fb8379901c42c0-media--image5.png

3. If you don’t have apache2 service you can use yum install to install the apache2 service in server.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_d1d3bf31e983401585fb8379901c42c0-media--image2.png

4. When you installed the httpd service it will not start the service automatically you have to start this manually using

systemctl restart httpd.service or service httpd restart

5. Add the new user for the httpd using

sudo htpasswd -c /etc/httpd/.htpasswd username

Here you have to use -c for the first user alone because it is used to create the specified file so in the first time it will create the specified file so no need to use this for next time.After executing this command it will ask for the password and Re-type the password.

6. After setting the password goto the configuration file of the domain here our configuration path file is /etc/httpd/conf.d here we can find the conf file if your domain config file is not you can create a new config file for your domain. In the extension of .conf

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_d1d3bf31e983401585fb8379901c42c0-media--image7.png

7. Here our config file is kumaran.conf . These are the content on the kumaran.conf file.

<VirtualHost *:80>

ServerName www.kumaran.com

ServerAlias www.kumaran.com

DocumentRoot /var/www/docs.thaaimann.com/html/kumaran

ErrorLog /var/www/docs.thaaimann.com/html/kumaran/error.log

CustomLog /var/www/docs.thaaimann.com/html/kumaran/access.log combined

<Directory "/var/www/docs.thaaimann.com/html/kumaran">

AuthType Basic

AuthName "Restricted Content"

AuthUserFile /etc/httpd/.htpasswd

Require valid-user

</Directory>

</VirtualHost>

Here we set the alias name as www.kumaran.com this will be used as the URL after completing all the steps here. Don't forget to change the AuthUserFile in the conf because it may vary for some people.

8. Have to include the .htaccess file in your domain file don't panic like the file is not created its a hidden file you can find by listing the hidden files using ls -la.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_d1d3bf31e983401585fb8379901c42c0-media--image8.png

9. Add these lines in the .htaccess file.

10. Congrats, that's all now you can able to see the authentication of your httpd or apache on your browser like this.

https://wiki.pheonixsolutions.com/index.php/File:Vertopal_d1d3bf31e983401585fb8379901c42c0-media--image10.png

11. After entering your username and password you can to go apache.

12. Here we have routed the file like the user to do this you can go the file in the location /etc/hosts open this hosts file and make the changes like

youripaddress domainname

xxxxxxxxxxxx www.kumaran.com

That's all after you hit the browser with the domain name it will redirect you to that page.

====END=====
[edit]