Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
How do I get Apache .htpasswd to work in this case?

I have a website running on an AWS EC2 Amazon Linux 2 AMI with Apache and PHP/Laravel. It's a test site though and I want to password-protect the site via .htpasswd. Even after following several tutorials, I can't seem to get it working. It's worth noting that the site works perfectly fine without the .htpasswd configuration.

When I try to set it up and go to the site, it prompts me for the user name and password, but upon properly entering them, I get the following error:

enter image description here

To set up the .htpasswd file, I ran the following commands:

cd ~
htpasswd -c .htpasswd project-name # Then input a password when prompted to.
sudo chown ec2-user:apache .htpasswd
sudo chmod 777 .htpasswd

I then added the following to the .htaccess file in the public directory of the Laravel project:

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/ec2-user/.htpasswd
Require valid-user

And when I try to load the site, I get the above error. If I comment out the four lines in the .htaccess file, then it works fine, but I can't get it to work otherwise. I'm not sure what's going on, as the Apache config is fairly straightforward.

If it matters, I did add a virtual host config to Apache's httpd.conf file. It looks something like this:

<VirtualHost *:80>
    ServerName ip-address
    DocumentRoot /var/www/project-name/public
    <Directory /var/www/project-name>
        AllowOverride All
    </Directory>
</VirtualHost>

Also, I'm not sure if it matters, but because this is a test site, there's no domain name associated with it. It's only accessible via an IP address.

I've tried restarting the Apache service and anything else I can think of, but to no avail. Does anyone have any thoughts as to what I might be doing wrong? Thank you.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I was having trouble viewing the Apache error log, which is why it was so difficult for me to see what was going on, but after figuring out how to access the error log, I saw that there was a permissions issue. I moved the .htpasswd file in the ec2-user home directory to a different location and it instantly worked. Thanks.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!