Re: Password Protecting a Directory using .htaccess

Top Page
Attachments:
Message as email
+ (text/plain)
+ (text/html)
+ (text/plain)
Delete this message
Reply to this message
Author: JD Austin via PLUG-discuss
Date:  
To: Main PLUG discussion list
CC: JD Austin
Subject: Re: Password Protecting a Directory using .htaccess
I just skimmed your email, but make sure selinux isn't causing you problems.
The .htaccess file has to have the right context or the web server won't be
able to access it.
Check to see what context it has eg: *ls -lhZ*
If it has a different context than the other files there it is likely the
reason for the error.

I'm running fedora, so my normal link I'd send you wouldn't be helpful.
I'm not sure where selinux messages are stored on ubuntu servers
(/var/log/secure is where it is on fedora).
These links might be helpful :
https://linuxhint.com/selinux-on-ubuntu-tutorial/
https://www.computernetworkingnotes.com/linux-tutorials/selinux-explained-with-examples-in-easy-language.html


On Mon, Jun 27, 2022 at 3:31 PM Keith Smith via PLUG-discuss <
> wrote:

>
>
> I wanted to password protect a directory. On it's face it is simple.
> Not for me today.
>
> Normal Steps
> 1) create the .htaccess in the appropriate directory and configure it
> properly.
> 2) create the .htpasswd file using the htpasswd command.
> 3) set permissions to both files to 644.
>
> So far so good, however it did not work.
>
> Been a few years so things have changed.
>
> I'm on Ubuntu 22.04lts and Apache 2.
>
> I assumed apache was automatically set to recognize the .htaccess and it
> appears to be set that way in the /etc/apache2/apache2.conf.
>
> Did not work.
>
> So I edited the /etc/apache2/apache2.conf as I found on the Inter Web
> Thingy....
>
> One website said to edit the /etc/apache2/apache2.conf file and replace
> the Directory code with
>
> <Directory /var/www/your_domain>
>    Options Indexes FollowSymLinks
>    AllowOverride All
>    Require all granted
> </Directory>

>
> That led to a server 500 error.
>
> My error.log said it was .htaccess: Unknown Authz provider which took me
> into a rabbit hole.
>
> So then I started many searches that lead me many places.....
>
> I tried adding
>
> <Directory /var/www/>
>          Options Indexes FollowSymLinks
>          AllowOverride None
>          Require all granted
> </Directory>

>
> to the default vhost : /etc/apache2/sites-available/000-default.conf
>
> Still no success - I thought the default settings were carried forward
> to other vhosts configurations? I guess not.
>
> Finally I added that code to the vhost I was trying to password protect
> and whala....
>
> I an a PHP dev, however I do "mess" with the LAMP stack on occasion.
>
> Did I miss something along the way? Seems I should have been able to
> define
>
> <Directory /var/www/>
>          Options Indexes FollowSymLinks
>          AllowOverride None
>          Require all granted
> </Directory>

>
> In the /etc/apache2/apache2.conf or
> /etc/apache2/sites-available/000-default.conf. Did I miss something?
>
> Thanks in advance!!
> ---------------------------------------------------
> PLUG-discuss mailing list -
> To subscribe, unsubscribe, or to change your mail settings:
> https://lists.phxlinux.org/mailman/listinfo/plug-discuss

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss