jonmrich
jonmrich

Reputation: 4323

Password protect directory in AWS EC2 running Apache/Linux

As the title says, I have an AWS EC2 instance with Apache. It's a Linux server. I want to password protect one directory. I was following this answer: https://stackoverflow.com/a/18178857/989722

htaccess:

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /var/www/admin/.htpasswd
Require valid-user

Created a proper .htpasswd file, but wondering if there's another step.

However, it's not working (i.e., directory isn't protected). I restarted my server and that didn't help. Wondering if I need to change something in my config file.

If I look at the contents of the directory where I placed my .htaccess file, using terminal ls, the .htaccess file isn't visible. I uploaded it using SFTP and see it using my FTP application, but maybe it's not actually there. Same thing for my .htpasswd file.

Upvotes: 1

Views: 5819

Answers (2)

NA SYD
NA SYD

Reputation: 51

Couple of addition to above step.

  1. config file to update directory for AllowOverride is available via vi editor sudo vi /etc/httpd/conf/httpd.conf

  2. After saving restart the apache server sudo /etc/init.d/httpd restart

Upvotes: 0

jonmrich
jonmrich

Reputation: 4323

Dumb mistake.

Needed to add this to my server config file:

<Directory /var/www/html/MYPROTECTEDDIRECTORY>
AllowOverride All     
</Directory>

Upvotes: 5

Related Questions