PKI kleines Projekt: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „==Ziel des Projektes== *Wir wollen einen Apache2 Webserver integrieren =Klonen der Maschine= {| class="wikitable" style="background-color: #f2f2f2;" ! Paramete…“) |
|||
| Zeile 1: | Zeile 1: | ||
==Ziel des Projektes== | ==Ziel des Projektes== | ||
| − | *Wir wollen einen Apache2 Webserver integrieren | + | *Wir wollen einen Apache2 Webserver auf dem ns integrieren |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
=Installation= | =Installation= | ||
Apache2 wird zusammen mit PHP und dem Apache-PHP-Modul installiert. | Apache2 wird zusammen mit PHP und dem Apache-PHP-Modul installiert. | ||
Version vom 3. August 2026, 12:43 Uhr
Ziel des Projektes
- Wir wollen einen Apache2 Webserver auf dem ns integrieren
Installation
Apache2 wird zusammen mit PHP und dem Apache-PHP-Modul installiert.
- sudo apt update
- sudo apt install -y apache2 php libapache2-mod-php
PHP aktivieren
Das PHP- und das SSL-Modul werden aktiviert. Damit die Änderung greift, muss Apache anschließend neu gestartet werden.
- sudo a2enmod php8.4 ssl
- sudo systemctl restart apache2
Webroot
Das Webroot-Verzeichnis ist der Standardort für Webseiten unter Apache.
- ls /var/www/html
Dynamische Testseite erstellen
Die Datei index.php ersetzt die Apache-Standardseite und gibt Systeminformationen aus.
- sudo vi /var/www/html/index.php
Inhalt der Datei:
<?php
$hostname = gethostname();
$ip = $_SERVER['SERVER_ADDR'];
$domain = php_uname('n');
// Gateway und Nameserver aus /etc/resolv.conf und ip route auslesen
$nameserver = shell_exec("awk '/^nameserver/{print $2; exit}' /etc/resolv.conf");
$gateway = shell_exec("ip route | awk '/^default/{print $3; exit}'");
?>
<!DOCTYPE html>
<html>
<head><title>Systeminfo</title></head>
<body>
<h1>Systeminfo</h1>
<table>
<tr><td>Hostname</td><td><?= htmlspecialchars($hostname) ?></td></tr>
<tr><td>IP-Adresse</td><td><?= htmlspecialchars($ip) ?></td></tr>
<tr><td>Domain</td><td><?= htmlspecialchars($domain) ?></td></tr>
<tr><td>Nameserver</td><td><?= htmlspecialchars(trim($nameserver)) ?></td></tr>
<tr><td>Gateway</td><td><?= htmlspecialchars(trim($gateway)) ?></td></tr>
</table>
</body>
</html>
Standardseite löschen
Die Apache-Standardseite wird gelöscht damit die neue PHP-Seite aufgerufen wird.
- sudo rm /var/www/html/index.html
Konfiguration der Seiten
- Verfügbare Konfigurationen
- DIR: /etc/apache2/sites-available/
- Aktivierten Konfigurationen
- DIR: /etc/apache2/sites-enabled
Neue Konfigurationen anlegen
- sudo vi /etc/apache2/sites-available/it.conf
<VirtualHost *:80>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/own.crt
SSLCertificateKeyFile /etc/ssl/own.key
</VirtualHost>
Aktivieren und deaktivieren
- deaktivieren der Default Seite
- sudo a2dissite 000-default.conf
- aktivieren unserer Seite
- sudo a2ensite it.conf
- Konfiguration testen und aktivieren
- sudo apache2ctl configtest
- sudo systemctl reload apache2
Testen
Im Browser die FQDN des Servers aufrufen.
- unverschlüsselt
- verschlüsselt
Handling und Kontrolle
- ss -lntp | egrep "80|443"
- systemctl start apache2
- systemctl stop apache2
- systemctl restart apache2
- systemctl reload apache2
- systemctl enable apache2
- systemctl disable apache2
- systemctl status apache2
- journalctl -fu apache2
- journalctl -xu apache2
- tail -f /var/log/apache2/access.log