Apache2 mit PHP (Debian): Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „= Installation und Test von Apache2 mit PHP = * apt install apache2 php libapache2-mod-php -y * systemctl enable --now apache2 * systemctl status apache2 --no…“) |
(→Testen) |
||
| (8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
= Installation und Test von Apache2 mit PHP = | = Installation und Test von Apache2 mit PHP = | ||
| − | |||
* apt install apache2 php libapache2-mod-php -y | * apt install apache2 php libapache2-mod-php -y | ||
* systemctl enable --now apache2 | * systemctl enable --now apache2 | ||
* systemctl status apache2 --no-pager | * systemctl status apache2 --no-pager | ||
| + | = Konfigurationsdatei = | ||
| + | Die Konfigurationsdatei sollte so aussehen | ||
| + | *cat /etc/apache2/sites-enabled/000-default.conf | ||
| + | <pre> | ||
| + | <VirtualHost *:80> | ||
| + | ServerAdmin technik@lab.int | ||
| + | DocumentRoot /var/www/html | ||
| + | ErrorLog ${APACHE_LOG_DIR}/error.log | ||
| + | CustomLog ${APACHE_LOG_DIR}/access.log combined | ||
| + | </VirtualHost> | ||
| + | </pre> | ||
= PHP-Testseite anlegen = | = PHP-Testseite anlegen = | ||
| Zeile 20: | Zeile 30: | ||
= Dynamischer Test (Hostname, Datum, Uhrzeit) = | = Dynamischer Test (Hostname, Datum, Uhrzeit) = | ||
| − | * | + | * nano /var/www/html/test.php |
| + | <pre> | ||
| + | <?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"); | ||
| + | ?> | ||
| + | </pre> | ||
* http://10.20.10.11/test.php im Browser aufrufen | * http://10.20.10.11/test.php im Browser aufrufen | ||
| Zeile 26: | Zeile 44: | ||
* journalctl -u apache2 -n 20 --no-pager | * journalctl -u apache2 -n 20 --no-pager | ||
* systemctl reload apache2 | * 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://debian-srv.lab.int | ||
| + | *tail -f /var/log/apache2/error_ssl.log | ||
Aktuelle Version vom 14. November 2025, 12:33 Uhr
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://debian-srv.lab.int
- tail -f /var/log/apache2/error_ssl.log