azure-templatesmoodle

Password-protect access to an application with Apache

To configure Apache to request a username and password when accessing your application, follow these steps:

  • At the console, type the following commands. Remember to replace APPNAME, USERNAME and PASSWORD with the application name (for example, wordpress) desired username and desired password respectively.

    $ cd /opt/bitnami
    $ sudo apache/bin/htpasswd -cb apache/APPNAME_users USERNAME PASSWORD
    
  • Edit the /opt/bitnami/apache/conf/vhosts/APPNAME-vhost.conf and /opt/bitnami/apache/conf/vhosts/APPNAME-https-vhost.conf files and modify them as shown below. You may also need to comment the Require all granted line as shown below:

    <Directory "/opt/bitnami/APPNAME">
      ...
      AuthType Basic
      AuthName MyAuthName
      AuthUserFile "/opt/bitnami/apache/APPNAME_users"
      Require valid-user
      Options -Indexes +FollowSymLinks -MultiViews
      AllowOverride None
      ...
    
      <IfVersion >= 2.3>
      # Require all granted
      </IfVersion>
      ...
    </Directory>
    
  • Restart the Apache server:

    $ sudo service bitnami restart
    

When accessing the application, you will see the following authentication popup window. Enter the username and password that you have defined in the first step:

Authentication required

To change the password later, run the htpasswd utility without the -c switch:

$ sudo /opt/bitnami/apache/bin/htpasswd /opt/bitnami/apache/APPNAME_users USERNAME
Last modification January 20, 2020