Apache2 mit PHP (Debian)
Version vom 13. November 2025, 17:03 Uhr von Thomas.will (Diskussion | Beiträge) (→SSL-vHost anpassen)
Installation und Test von Apache2 mit PHP
- apt install apache2 php libapache2-mod-php -y
- systemctl enable --now apache2
- systemctl status apache2 --no-pager
Konfigurationsdatei
Die Konfigurationsdatei sollte so aussehen
- cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin technik@lab.int
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
PHP-Testseite anlegen
- echo "<?php phpinfo(); ?>" > /var/www/html/info.php
- chmod 644 /var/www/html/info.php
- ls -l /var/www/html/info.php
Browser-Test
Im Browser aufrufen: http://10.20.10.11/info.php
Es sollte eine Seite mit den PHP-Informationen erscheinen (PHP Version, Module, Build-Datum etc.)
Logprüfung
- tail -f /var/log/apache2/access.log
- tail -f /var/log/apache2/error.log
Dynamischer Test (Hostname, Datum, Uhrzeit)
- nano /var/www/html/test.php
<?php
echo "<h2>Serverstatus</h2>";
echo "Hostname: " . gethostname() . "<br>";
date_default_timezone_set("Europe/Berlin");
echo "Datum und Uhrzeit: " . date("Y-m-d H:i:s");
?>
- http://10.20.10.11/test.php im Browser aufrufen
Kontrolle
- journalctl -u apache2 -n 20 --no-pager
- systemctl reload apache2
TLS aktivieren (mit Wildcard-Zertifikat für *.lab.int)
- a2enmod ssl
- a2ensite default-ssl
Zertifikate ablegen
- wget https://web.samogo.de/certs/lab.int/ca.crt
- wget https://web.samogo.de/certs/lab.int/star.lab.int.crt
- wget https://web.samogo.de/certs/lab.int/star.lab.int.key
- cp star.lab.int.crt /etc/ssl/certs/
- cp star.lab.int.key /etc/ssl/private/
- cp ca.crt /etc/ssl/certs/
SSL-vHost anpassen
- vi /etc/apache2/sites-available/default-ssl.conf
<VirtualHost _default_:443>
ServerAdmin technik@lab.int
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/certs/star.lab.int.crt
SSLCertificateKeyFile /etc/ssl/private/star.lab.int.key
SSLCertificateChainFile /etc/ssl/certs/ca.crt
ErrorLog ${APACHE_LOG_DIR}/error_ssl.log
CustomLog ${APACHE_LOG_DIR}/access_ssl.log combined
</VirtualHost>
Neustart
- systemctl reload apache2
Testen
Im Browser: https://server.lab.int
- tail -f /var/log/apache2/error_ssl.log