Apache2 mit PHP (Debian): Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 3: | Zeile 3: | ||
* 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 webmaster@localhost | ||
| + | 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 = | ||
Version vom 13. November 2025, 16:55 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 webmaster@localhost
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