Password protected frontend

Hi, I tried to protect my frontend with a password. I used this guide --> https://docs.bitnami.com/aws/infrastructure/lamp/administration/use-htpasswd/

I don´t know why but it didn´t work. Can anybody explain this part:

Edit the /opt/bitnami/apps/APPNAME/conf/httpd-app.conf file and add the following lines. You also need to comment the Require all granted line as shown below:

<Directory "/opt/bitnami/apps/APPNAME/htdocs">
  ...
    AuthType Basic
    AuthName MyAuthName
    AuthUserFile "/opt/bitnami/apache2/APPNAME_users"
    Require valid-user
  ...

  <IfVersion >= 2.3>
  # Require all granted
  </IfVersion>
  ...
</Directory>

Thank you!

There’s a few options depending on your requirements. Checkout options 2, 3 or 4 in Prevent development server getting indexed by google - #2 by digitalstartup. If it’s just during development then I tend to use option 4.

However, in reference to the code you’re referring to - You need to swap out

<Directory "/opt/bitnami/apps/APPNAME/htdocs">

with your actual web directory where you have Magento install. So, if you’ve been following along with my guides/tutorials then this would be /var/www/html/`, so the line would be:

<Directory "/var/www/html">

And then this next line will vary depending on the apache configuration locations (whatever you ahve it set as:

AuthUserFile "/opt/bitnami/apache2/APPNAME_users"

Note: The instructions refer to a very specific type of setup. Probably One-Click Install in either a Shared Environment of one where something like cPanel/Plesk is installed? I don’t work on these environments so my knowledge is lacking on troubleshooting them.

1 Like

Hi Craig,

thanks for your feedback!

I sat up my server on AWS Lightsail. The documentation from bitnami about " Password-Protect Access To An Application With Apache" should match with one click server configuration.

The first step is:

At the console, type the following commands. Remember to replace APPNAME, USERNAME and PASSWORD with your application name, desired username and desired password respectively.

cd /opt/bitnami
apache2/bin/htpasswd -cb apache2/APPNAME_users USERNAME PASSWORD

–> that worked out.

The second step:

Edit the /opt/bitnami/apps/APPNAME/conf/httpd-app.conf file and add the following lines. You also need to comment the Require all granted line as shown below:

I am not sure what “You also need to comment the Require all granted line as shown below” mean?

<Directory "/opt/bitnami/apps/APPNAME/htdocs">
  ...
    AuthType Basic
    AuthName MyAuthName
    AuthUserFile "/opt/bitnami/apache2/APPNAME_users"
    Require valid-user
  ...

  <IfVersion >= 2.3>
  # Require all granted
  </IfVersion>
  ...
</Directory>

My original httpd-app.conf file looks like that:

<IfDefine USE_PHP_FPM>
    <Proxy "unix:/opt/bitnami/php/var/run/magento.sock|fcgi://magento-fpm" timeout=300>
    </Proxy>
</IfDefine>

<Directory "/opt/bitnami/apps/magento/htdocs">

    Options -MultiViews
    AllowOverride None
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>

    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>
    
    <IfDefine USE_PHP_FPM>
       <FilesMatch \.php$>
         SetHandler "proxy:fcgi://magento-fpm"
       </FilesMatch>
    </IfDefine>

    
                        <IfModule pagespeed_module>
                        ModPagespeedDisallow "*"
                        </IfModule>

       
    Include "/opt/bitnami/apps/magento/conf/banner.conf"
</Directory>

Include "/opt/bitnami/apps/magento/conf/htaccess.conf"

I am not sure where to add these lines in the original file. Additionally I am not sure how to understand the second step of the Bitnami documentation. Maybe you can help me out?

Best,
Dominik

As I mentioned, I’m not familiar with Bitnami so your httpd configs are a bit foreign to me. But let’s try and break this down into working examples…

Note how I’ve amended all references of:

  • APPNAME to magento
  • USERNAME to bob
  • PASSWORD to password1

Step 1: So, you’ve navigated to the /opt/bitnami directory and then executed the username/password command:

apache2/bin/htpasswd -cb apache2/magento_users bob password1

Step 2: And then you would have added the 4 Auth lines and commented out the Require all line:

<IfDefine USE_PHP_FPM>
    <Proxy "unix:/opt/bitnami/php/var/run/magento.sock|fcgi://magento-fpm" timeout=300>
    </Proxy>
</IfDefine>

<Directory "/opt/bitnami/apps/magento/htdocs">

    AuthType Basic
    AuthName MyAuthName
    AuthUserFile "/opt/bitnami/apache2/magento_users"
    Require valid-user

    Options -MultiViews
    AllowOverride None
    <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
    </IfVersion>

    <IfVersion >= 2.3>
        # Require all granted
    </IfVersion>
    
    <IfDefine USE_PHP_FPM>
       <FilesMatch \.php$>
         SetHandler "proxy:fcgi://magento-fpm"
       </FilesMatch>
    </IfDefine>

    <IfModule pagespeed_module>
       ModPagespeedDisallow "*"
    </IfModule>
       
    Include "/opt/bitnami/apps/magento/conf/banner.conf"
</Directory>

Include "/opt/bitnami/apps/magento/conf/htaccess.conf"

Step 3: And then you would have restarted apache for the changes to take effect

This is how I read the instructions anyway. I obviously have no way of testing these instructions.

1 Like

Hi Craig,

thank you very much for your help. Highly appreciated!

I´ve done that in the exact same way but it didn´t work out. You think that has something to do with the write/read authority?

Best,
Dominik

Sorry to hear that. A complete stab in the dark would be to move # Require all granted directly underneath Require valid-user. As I guess that would apply to everything under the web directory rather than anything in the IFVersion rule. For example:

    AuthType Basic
    AuthName MyAuthName
    AuthUserFile "/opt/bitnami/apache2/magento_users"
    Require valid-user
    # Require all granted

But honestly you’re best off consulting a Unix Specialist forum such as https://unix.stackexchange.com to solve this.

1 Like