0

I'm setting up basic http authentication for my subdomain dev Laravel site with .htaccess and .htpasswd.

First, I created my .htpasswd user and password by command htpasswd -bc .htpasswd admin passadmin. Then, my htaccess file with some basic configurations. I placed my .htaccess file on my project directory /home/user/public_html/laravel_project Then .htpasswd file in /home/user/.htpasswds/.htpasswd.

Also in my apache configuration file, I have AllowOverride All

.htaccess code:

AuthType Basic
AuthName "Site Administratrion"
AuthBasicProvider file
AuthUserFile "/home/user/.htpasswds/.htpasswd"
Require user admin

After all those configurations, I cleared my cache and tested. At first asks normally for credentials, the login page of my site loads but after i login asks again for htpasswd credentials and throws an ERROR 401 Unauthorized.

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

By the way, I don't have apache logs on this problem.

Is it Laravel/React related? I need aditional configurations? I think i've tried almost anything.

  • 2
    Why don't you have Apache logs? This type of problem is nearly impossible to debug unless you see the logging. – Stephen Ostermiller Aug 12 at 23:00
  • "file in /home/user/.htpasswds/.htpasswd" - maybe a typo, but that differs from the .htaccess directive you posted. Since you are accessing the login page of your site successfully (only with the correct credentials I assume) then the HTTP authentication would seem to be working OK. (Do you have two levels of authentication?) "Is it Laravel/React related?" - This would be my guess. I imagine there might be some AJAX requests that don't have the necessary Authentication headers; hence the repeated password requests. But the network traffic or the log files would confirm this. – MrWhite Aug 13 at 21:02
  • Sorry for the typo, i've updated the code. I login via an JWT json authentication in Laravel. This may be the problem? – francisco cueva Aug 14 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.