Apache2 mit PHP (Debian)

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

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");
?>

Kontrolle

  • journalctl -u apache2 -n 20 --no-pager
  • systemctl reload apache2