Apache : setup basic auth with apache in windows



Authentication is any process by which you verify that someone is who they claim they are. Authorization is any process by which someone is allowed to be where they want to go or to have information that they want to have.

I will show here how to set up basic auth on the apache with windows.

Pre-requests 

Windows VPS

Apache server ( That's it )
( In windows it might be difficult to setup the Apache alone. So instead use something ling xampp, wamp or laragon.)

RestClient

(  I personally use the postman, but you can use your preferable client) 



Windows VPS provider


Steps 

  • Enable the necessary modules in the Apache
  • Create the password file
  • Set the auth directives in the virtual host file.
  • Verify basic auth.

Enable the necessary modules in the Apache

Open the httpd.conf file in the apache's conf folder.


httpd.conf file
httpd.conf file

Enable the necessary modules to make the basic auth working.

Necessary modules 

  • mod_auth_basic
  • mod_authn_file



Enable the necessary modules
Enable the necessary modules

Restart the apache to make the modules active.


Create Password File


You need to create a password file before you can use it for the basic auth. To create a password file you have to use the htpasswd.exe( it comes with the apache itself. You can find it inside the bin folder of the Apache server )
htpasswd.exe to create password file

Create a password using the htpasswd.exe

create basic auth passwrod file
create basic auth password file

verify that file has actually created.

the password file
the password file




Set the auth directives in the virtual host file



<VirtualHost *:80>
 ServerName xx.xx.xxx.xxx 
        ServerAlias alias 
        <location / >
  AuthType Basic
  AuthName "Restricted Routes"
  # (Following line optional)
  AuthBasicProvider file
  AuthUserFile "C:\auth\passwords"
  Require user mansih
 </location>
</VirtualHost>




Set the location to the URL you want to enable the basic auth on.

For example, if you want to secure the /login with basic auth then replace <location /> to <location /login>
To read more about location click here. Apache location

After updating the virtual host file reload the apache to make the basic auth working.

Verify basic auth.


I am using the postman to verify the basic auth.

In case of valid username and password, you will get the 200 HTTP response.

postman 200 HTTP response
postman 200 HTTP response
In case of invalid username and/or password, you will get the 200 HTTP response.

postman 401 HTTP response
postman 401 HTTP response


Hope you find it useful. 
Have a nice Day !

Comments

  1. Marvelous, Very useful post, Thank You for the information, Keep it up.
    Abhishek Rawat

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. Thank you for sharing information.It was very useful.
    Well done

    ReplyDelete
  7. HI,
    You have written very good informative information about latest topic. You have given great information article that will be very useful for me. I want to know more information deeply about it.

    ReplyDelete
  8. Thanks for taking the time to talk about this, I feel strongly about it and really like mastering more on this subject. If feasible, as you acquire experience, would you mind updating your blog with much more information and facts? It is very helpful for me.

    ReplyDelete
  9. Thank You for the information, Keep it up.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. Great post. Keep writing such kind of info on your page. Will used it up for my site SBObet :)

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Thank you very much for your great information. It really makes me happy and I am satisfied with the arrangement of your post. You are really a talented person I have ever seen. I will keep following you forever. If you have time you can check this site and give me a suggestion.
    phoenix down pillows

    ReplyDelete
  14. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.

    hotmail.com

    ReplyDelete

Post a Comment

Popular Posts