Apache HTTP Server — Webserver konfigurieren und betreiben

Praxis-Guide zum Apache HTTP Server — Dienststeuerung, configtest, VirtualHosts, Module, TLS und Directives auf Debian/Ubuntu und RHEL.

Der Apache HTTP Server – oft schlicht httpd genannt – gehört seit Jahrzehnten zu den meistgenutzten Webservern im Internet. Sein modularer Aufbau lässt dich Funktionen wie mod_rewrite, SSL oder Reverse-Proxy gezielt zuschalten, und über VirtualHosts bedienst du beliebig viele Domains aus einer einzigen Instanz. Dieses Cheat-Sheet bündelt die Befehle, die du im Alltag brauchst: Dienststeuerung, Konfigurationstests, Module, VirtualHosts, TLS und Performance-Tuning. Prüfe vor jedem Reload die Syntax mit apachectl configtest – und nutze graceful statt eines harten Neustarts, um laufende Verbindungen nicht abzuwürgen.

Dienststeuerung (systemctl)

systemctl start apache2 — Startet den Apache-Webserver (Debian/Ubuntu). Auf RHEL/CentOS httpd verwenden.

systemctl start apache2

systemctl stop apache2 — Stoppt den Apache-Webserver geordnet.

systemctl stop apache2

systemctl restart apache2 — Startet Apache neu (stoppt und startet). Trennt kurzzeitig alle aktiven Verbindungen.

systemctl restart apache2

systemctl reload apache2 — Lädt die Apache-Konfiguration neu, ohne aktive Verbindungen zu trennen (graceful).

systemctl reload apache2

systemctl status apache2 — Zeigt Dienststatus, PID und die letzten Logausgaben von Apache.

systemctl status apache2

systemctl enable apache2 — Aktiviert den automatischen Start von Apache beim Systemstart.

systemctl enable apache2

systemctl disable apache2 — Deaktiviert den automatischen Start von Apache beim Booten.

systemctl disable apache2

apachectl-Kommandos

apachectl configtest — Prüft die Apache-Konfiguration auf Syntaxfehler. Gibt „Syntax OK" oder einen Fehler zurück.

apachectl configtest

apachectl -t — Kurzform von configtest. Prüft die Konfigurationssyntax.

apachectl -t

apachectl -t -D DUMP_VHOSTS — Zeigt eine Übersicht aller konfigurierten VirtualHosts mit ServerName und DocumentRoot.

apachectl -t -D DUMP_VHOSTS

apachectl -t -D DUMP_MODULES — Listet alle geladenen Apache-Module auf.

apachectl -t -D DUMP_MODULES

apachectl -t -D DUMP_RUN_CFG — Zeigt die aufgelöste Laufzeit-Konfiguration (MPM-Einstellungen, ServerName usw.).

apachectl -t -D DUMP_RUN_CFG

apachectl -v — Zeigt die Apache-Version und das Build-Datum.

apachectl -v

apachectl -V — Zeigt Version, Build-Flags und einkompilierte Standardwerte von Apache.

apachectl -V

apachectl graceful — Lädt die Apache-Konfiguration geordnet neu (ohne Verbindungen zu trennen).

apachectl graceful

apachectl graceful-stop — Stoppt Apache geordnet, nachdem die laufenden Requests abgeschlossen sind.

apachectl graceful-stop

Module (Debian/Ubuntu)

a2enmod <module> — Aktiviert ein Apache-Modul. Legt Symlinks in mods-enabled/ an. Erfordert Reload/Restart.

a2enmod rewrite

a2dismod <module> — Deaktiviert ein Apache-Modul. Entfernt Symlinks aus mods-enabled/. Erfordert Reload.

a2dismod status

a2enmod rewrite && systemctl reload apache2 — Aktiviert mod_rewrite und lädt Apache in einem Schritt neu.

a2enmod rewrite && systemctl reload apache2

a2enmod ssl headers deflate expires — Aktiviert mehrere Module auf einmal.

a2enmod ssl headers deflate expires

apache2ctl -M — Listet alle aktuell geladenen (statischen und dynamischen) Apache-Module auf.

apache2ctl -M

apache2ctl -M | grep <module> — Prüft, ob ein bestimmtes Modul aktuell geladen ist.

apache2ctl -M | grep rewrite

VirtualHosts (Debian/Ubuntu)

a2ensite <config> — Aktiviert eine VirtualHost-Konfigurationsdatei aus sites-available/. Legt einen Symlink in sites-enabled/ an.

a2ensite example.com.conf

a2dissite <config> — Deaktiviert eine VirtualHost-Konfigurationsdatei. Entfernt den Symlink aus sites-enabled/.

a2dissite 000-default.conf

a2ensite example.com.conf && systemctl reload apache2 — Aktiviert einen VirtualHost und lädt Apache in einem Schritt neu.

a2ensite example.com.conf && systemctl reload apache2

ls /etc/apache2/sites-enabled/ — Listet alle aktuell aktivierten VirtualHost-Konfigurationen auf.

ls /etc/apache2/sites-enabled/

ls /etc/apache2/sites-available/ — Listet alle verfügbaren VirtualHost-Konfigurationsdateien auf.

ls /etc/apache2/sites-available/

apachectl -t -D DUMP_VHOSTS 2>&1 | grep -A3 'example.com' — Findet heraus, welche VirtualHost-Konfiguration eine bestimmte Domain bedient.

apachectl -t -D DUMP_VHOSTS 2>&1 | grep -A3 'example.com'

Logs

tail -f /var/log/apache2/access.log — Verfolgt das Apache-Access-Log in Echtzeit (Debian/Ubuntu).

tail -f /var/log/apache2/access.log

tail -f /var/log/apache2/error.log — Verfolgt das Apache-Error-Log in Echtzeit.

tail -f /var/log/apache2/error.log

tail -f /var/log/httpd/access_log — Verfolgt das Apache-Access-Log auf RHEL/CentOS.

tail -f /var/log/httpd/access_log

grep 'error\|crit\|alert\|emerg' /var/log/apache2/error.log — Durchsucht das Error-Log nach Meldungen der Stufen Critical und Error.

grep 'error\|crit\|alert\|emerg' /var/log/apache2/error.log

apache2ctl status — Zeigt eine Live-Serverstatus-Seite im Terminal an (erfordert mod_status).

apache2ctl status

apachectl -e debug -k start — Startet Apache mit Error-Logging auf Debug-Stufe zur Fehlersuche.

apachectl -e debug -k start

SSL / TLS

a2enmod ssl && a2ensite default-ssl.conf && systemctl reload apache2 — Aktiviert das SSL-Modul und den Standard-SSL-VirtualHost (Debian/Ubuntu).

a2enmod ssl && a2ensite default-ssl.conf && systemctl reload apache2

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt — Erzeugt ein selbstsigniertes SSL-Zertifikat mit 365 Tagen Gültigkeit.

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt

openssl s_client -connect <host>:443 -servername <host> — Testet eine SSL-Verbindung und prüft die Zertifikatskette.

openssl s_client -connect example.com:443 -servername example.com

openssl x509 -in server.crt -text -noout — Zeigt die Details einer SSL-Zertifikatsdatei an (Ablauf, Aussteller, SANs).

openssl x509 -in server.crt -text -noout

certbot --apache -d <domain> — Bezieht und installiert automatisch ein Let's-Encrypt-SSL-Zertifikat für Apache.

certbot --apache -d example.com -d www.example.com

certbot renew --dry-run — Testet den automatischen Erneuerungsprozess für Let's-Encrypt-Zertifikate.

certbot renew --dry-run

Konfigurationsverzeichnisse

/etc/apache2/apache2.conf — Haupt-Konfigurationsdatei von Apache auf Debian/Ubuntu.

nano /etc/apache2/apache2.conf

/etc/httpd/conf/httpd.conf — Haupt-Konfigurationsdatei von Apache auf RHEL/CentOS/Fedora.

nano /etc/httpd/conf/httpd.conf

/etc/apache2/sites-available/ — Verzeichnis mit allen VirtualHost-Definitionsdateien (Debian/Ubuntu).

ls /etc/apache2/sites-available/

/etc/apache2/conf-available/ — Verzeichnis für zusätzliche Konfigurations-Snippets (Debian/Ubuntu).

ls /etc/apache2/conf-available/

/etc/apache2/mods-available/ — Verzeichnis mit allen verfügbaren Modul-Konfigurationsdateien.

ls /etc/apache2/mods-available/

a2enconf <config> && systemctl reload apache2 — Aktiviert ein Konfigurations-Snippet aus conf-available/.

a2enconf php8.2-fpm && systemctl reload apache2

a2disconf <config> — Deaktiviert ein Konfigurations-Snippet aus conf-enabled/.

a2disconf security

VirtualHost-Konfiguration

Einfacher HTTP-VirtualHost-Block mit ServerName, DocumentRoot und separaten Logdateien.

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

HTTPS-VirtualHost-Block mit SSL-Zertifikatskonfiguration.

<VirtualHost *:443>
    ServerName example.com
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/example.crt
    SSLCertificateKeyFile /etc/ssl/private/example.key
    DocumentRoot /var/www/html/example
</VirtualHost>

Directory-Block, der Zugriff gewährt und .htaccess-Overrides aktiviert (AllowOverride All).

<Directory /var/www/html/example>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Blendet Apache-Version und Betriebssystem aus HTTP-Headern und Fehlerseiten aus (in apache2.conf eintragen).

ServerTokens Prod
ServerSignature Off

Reverse-Proxy: leitet /api/-Requests an eine Backend-App auf Port 3000 weiter (erfordert mod_proxy).

ProxyPass /api/ http://localhost:3000/
ProxyPassReverse /api/ http://localhost:3000/

Performance & Tuning

apache2ctl -V | grep 'MPM' — Prüft, welches MPM (Multi-Processing Module) aktiv ist: prefork, worker oder event.

apache2ctl -V | grep 'MPM'

a2dismod mpm_prefork && a2enmod mpm_event && systemctl restart apache2 — Wechselt von prefork zum performanten event-MPM (für HTTP/2 erforderlich).

a2dismod mpm_prefork && a2enmod mpm_event && systemctl restart apache2

a2enmod http2 && systemctl reload apache2 — Aktiviert HTTP/2-Unterstützung (erfordert mpm_event und SSL).

a2enmod http2 && systemctl reload apache2

ab -n 1000 -c 10 https://example.com/ — Apache Bench: sendet 1000 Requests mit 10 gleichzeitigen Verbindungen, um eine URL zu benchmarken.

ab -n 1000 -c 10 https://example.com/

ab -n 500 -c 20 -H "Accept-Encoding: gzip" http://example.com/ — Benchmark mit gzip-Encoding-Header, um die Komprimierungs-Performance zu testen.

ab -n 500 -c 20 -H "Accept-Encoding: gzip" http://example.com/

curl -I -H 'Accept-Encoding: gzip' http://example.com/ — Prüft, ob gzip-Komprimierung (mod_deflate) für eine URL aktiv ist.

curl -I -H 'Accept-Encoding: gzip' http://example.com/

Fazit

Apache bleibt die robuste, breit unterstützte Wahl für klassisches Webhosting – besonders dort, wo .htaccess-Overrides, ausgereifte Module und jahrzehntelange Dokumentation zählen. Prüfe Konfigurationsänderungen immer erst mit apachectl configtest und rolle sie per graceful-Reload aus, dann bleibt dein Server auch im laufenden Betrieb stabil. Wer maximale Performance braucht, kombiniert das event-MPM mit HTTP/2 und mod_deflate.

Verwandte Kommandos

  • caddy – moderner Webserver mit automatischem HTTPS
  • certbot – Let's-Encrypt-Zertifikate beziehen und erneuern
  • ferron – schlanker, in Rust geschriebener Webserver