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