Password Protecting a Directory using .htaccess

techlists at phpcoderusa.com techlists at phpcoderusa.com
Mon Jun 27 15:31:33 MST 2022



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!!


More information about the PLUG-discuss mailing list