Basic password auth

Updated: 26 March 2024

Create a password file for user mrfoo

sudo htpasswd -c /etc/apache2/.htpasswd mrfoo

In the Virtual Host definition, set the directory for protection and require a valid user

<VirtualHost *:80>
    ServerAdmin chris@christaylordeveloper.co.uk
    ServerName example.com
    DocumentRoot /var/www/example.com/public
    <Directory "/var/www/example.com/public">
        AuthType Basic
        AuthName "Private area"
        AuthUserFile /etc/apache2/.htpasswd
        Require valid-user
    </Directory>
</VirtualHost>

Web server log format

Updated: 10 September 2022

Logs to
/var/log/apache2

Use directive
CustomLog ${APACHE_LOG_DIR}/access.log chrisdebug

example

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{Host}i\" \"%{User-agent}i\"" chrisdebug

example

LogFormat "\nNEW ENTRY:\nReferer: \"%{Referer}i\"\nHost: \"%{Host}i\"\nX-Forwarded-Host: \"%{X-Forwarded-Host}i\"\nX-Forwarded-For: \"%{X-Forwarded-For}i\"\nX-Forwarded-Proto: \"%{X-Forwarded-Proto}i\"\nX-Forwarded-Port: \"%{X-Forwarded-Port}i\"" chrisdebug

Apache

Updated: 27 September 2024

Webserver configuration might be found at

/etc/apache2

Start and stop

sudo service apache2 restart
sudo systemctl reload apache2

Enable and disable a site

sudo a2ensite example.com.conf
sudo a2dissite example.com.conf

Check config

apachectl configtest