Skip to main content

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. 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
  14. thanks for sharing informative information.

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

    ReplyDelete

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

    ReplyDelete
  17. 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.

    ReplyDelete
  18. 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     

    ReplyDelete
  19. 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     

    ReplyDelete
  20. Thanks for sharing this informative information with us. It is a well-written article in simple words I like it. For more info about website redesign company and the best web development company in india then just visit.

    ReplyDelete
  21. Its been a great thing that were are witnessing right now.
    Brother Printer Sleep Mode Off

    ReplyDelete
  22. Thanks for sharing such an amazing blog with us I really like to read such type of article.
    Domain & web hosting

    ReplyDelete
  23. Thanks for sharing nice information with us. I like your post and share your post with my friends. Keep sharing. AOL mail

    ReplyDelete
  24. Very well and great blog thanks admin for sharing such a great and super blog

    How Tall Are Bears

    ReplyDelete
  25. Thanks for the share, truly amazing. Also, check this out if you are looking for professional website or logo design services:


    Buy Logo

    ReplyDelete
  26. This is truly amazing, thanks for the share. Also, check this out if you are looking for professional website or logo design services:


    Buy Logo

    ReplyDelete
  27. If you are looking for remote shelter and embarking on an adventurous evening out,creek park dubai is not the right place for you. Visitors can enjoy many outdoor activities that will entice anyone and keep them away from their busy and monotonous schedule.

    creek park dubai is the second largest park in Dubai, with endless acres of meadows, children's playgrounds and gardens.

    In 1994, creek park dubai opened and is one of the oldest and largest parks in Dubai. The park is bordered by a saltwater spring.

    ReplyDelete
  28. Being somebody who anticipates praising the New Year 2021 with their loved ones, you need to wish them well. Through our correspondence, people are understood what you can use to build up cheerful relations with individuals. Thus, on New Year's Eve, we present to you some beautiful New Year Wishes for companions, family, spouse, sweetheart, and other new year wishes good tidings.
    New Year Resolution

    ReplyDelete

Post a Comment

Popular posts from this blog

Google blogger Ideas panel

Google blogger Ideas  I opened by blogger today, and..   I got this.  Google blogger Ideas  A panel suggesting a topic on which I can write my next blog. It's fetching unanswered question from web according to your previous post and topics. It was something, I was really looking for, after all it takes time to finding subject on which to write next and still being in the same niche.  Awesome feature Blogger! 

Firebase - update a spacific fields of single element of object of array in firestore

Firebase - update a spacific fields of single element of object of array in firestore  Its actully advisable to use map instead of array when ever it is possible. But, there are cetain cases where you don't have option to do so.  For example, you are directly saving the response from some outer source without any modification and they send you an array. In this case you will have array to work with. Firestore does not support array here is why  "bad things can happen if you have multiple clients all trying to update or delete array elements at specific indexes. In the past, Cloud Firestore addressed these issues by limiting what you can do with arrays " For more details information you can refer to Kato Richardson post Best Practices: Arrays in Firebase .  Firestore document having array [ used from stackoverflow question ] Suppose you have array of object something like shown in array. Now you want to update endTime field of the object on the index [1]