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.


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.)


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

Windows VPS provider


  • 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

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 !


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

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

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

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

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

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

  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.

  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.

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

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

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

  12. This comment has been removed by the author.

  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

  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.


  15. Thanks for sharing nice information with us. I like your post and all you share with us is up to date and quite informative, I would like to bookmark the page so I can come here again to read you, as you have done a wonderful job.
    Any blog info

  16. thanks for sharing informative information.

  17. i find this article is very useful for me atleast.
    desert safari dubai


  18. I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if that's cool. Thanks

    Staten Island Ferry

  19. Very engaging post keep posting more.
    Beautiful article will keep visiting this site for more blogs. thank you
    Great post, keep sharing your post so that it may inspire more people. Thank you.
    FivoTech is one of the fastest growing SEO agency in Chennai, We provide the complete solution of digital marketing.
    Where we help to rank your website and give the best ROI.

  20. Your post is very unique and reliable information for all readers to write more on the same topic and share with us your info...Thanks, Slide Business     


Post a Comment

Popular posts from this blog

Sciter : GUI Application with Golang using HTML/CSS

setup hyperledger fabric on windows 10

Host Multiple Web Sites of Go Using Reverse Proxy Example