apache httpd reference

key paths (debian/ubuntu)

service control

ActionCommand
Start/Stop/Restartsudo systemctl start|stop|restart apache2
Reload configsudo systemctl reload apache2
Enable at bootsudo systemctl enable apache2
Check statussystemctl status apache2

config checks

TaskCommand
Syntax testsudo apachectl configtest
List loaded modulesapachectl -M
Virtual host mapapachectl -S

enable/disable vhosts & modules

ActionCommand
Enable sitesudo a2ensite example.conf
Disable sitesudo a2dissite example.conf
Enable modulesudo a2enmod rewrite
Disable modulesudo a2dismod php8.2
Reload after changessudo systemctl reload apache2

minimal virtual host (http)

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    ErrorLog ${APACHE_LOG_DIR}/example-error.log
    CustomLog ${APACHE_LOG_DIR}/example-access.log combined
</VirtualHost>

redirect http→https

<VirtualHost *:80>
    ServerName example.com
    RewriteEngine On
    RewriteRule ^/(.*)$ https://example.com/$1 [R=301,L]
</VirtualHost>

basic auth snippet

<Directory /var/www/secure>
    AuthType Basic
    AuthName \"Restricted\"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
</Directory>
# create user: htpasswd -c /etc/apache2/.htpasswd alice

ssl (with let's encrypt)

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com
sudo systemctl reload apache2

performance knobs

logs and debugging

common errors & fixes

Return to Home