Apache2 Web Server
In diesem Tutorial lernst du, wie du den Apache2 Web Server auf einem Linux-System installierst, konfigurierst und deine erste Website damit hostest.
In this tutorial you will learn how to install, configure and host your first website with the Apache2 web server on a Linux system.
Apache2 installieren
Install Apache2
Zuerst aktualisieren wir die Paketliste und installieren den Apache2 Webserver:
First, update the package list and install the Apache2 web server:
sudo apt update
sudo apt install apache2 -yApache2 starten und aktivieren
Start and enable Apache2
Starte den Apache2-Dienst und aktiviere ihn, damit er beim Systemstart automatisch läuft:
Start the Apache2 service and enable it so it runs automatically on boot:
sudo systemctl start apache2
sudo systemctl enable apache2Überprüfe den Status des Dienstes:
Check the status of the service:
sudo systemctl status apache2Installation überprüfen
Verify the installation
Teste ob Apache2 korrekt funktioniert, indem du die Standard-Seite über curl abrufst:
Test whether Apache2 is working correctly by fetching the default page with curl:
curl localhostDu solltest HTML-Code der Apache2-Standardseite sehen. Du kannst auch im Browser http://localhost oder http://DEINE-IP aufrufen.
You should see the HTML code of the Apache2 default page. You can also visit http://localhost or http://YOUR-IP in your browser.
Document Root verstehen
Understand the Document Root
Das Standard-Webverzeichnis von Apache2 befindet sich unter /var/www/html. Hier liegt die Datei index.html, die beim Aufrufen der Seite angezeigt wird.
The default web directory of Apache2 is located at /var/www/html. This is where the index.html file is stored that gets displayed when visiting the site.
ls -la /var/www/html/Du kannst die Standardseite bearbeiten oder durch deine eigene Website ersetzen:
You can edit the default page or replace it with your own website:
sudo nano /var/www/html/index.htmlVirtualHost-Konfiguration erstellen
Create a VirtualHost configuration
Mit VirtualHosts kannst du mehrere Websites auf einem Server betreiben. Erstelle ein neues Verzeichnis für deine Seite und eine Konfigurationsdatei:
VirtualHosts allow you to run multiple websites on a single server. Create a new directory for your site and a configuration file:
sudo mkdir -p /var/www/meine-seite
sudo chown -R $USER:$USER /var/www/meine-seiteErstelle eine Beispiel-HTML-Datei:
Create a sample HTML file:
echo '<h1>Meine Website läuft!</h1>' > /var/www/meine-seite/index.htmlErstelle nun die VirtualHost-Konfigurationsdatei unter /etc/apache2/sites-available/:
Now create the VirtualHost configuration file in /etc/apache2/sites-available/:
sudo nano /etc/apache2/sites-available/meine-seite.confFüge folgenden Inhalt ein:
Paste the following content:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName meine-seite.local
DocumentRoot /var/www/meine-seite
<Directory /var/www/meine-seite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Seite aktivieren mit a2ensite
Enable the site with a2ensite
Aktiviere die neue Seite mit dem Befehl a2ensite und deaktiviere optional die Standard-Seite:
Enable the new site with the a2ensite command and optionally disable the default site:
sudo a2ensite meine-seite.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2Teste ob die Konfiguration gültig ist:
Test whether the configuration is valid:
sudo apache2ctl configtestDie Ausgabe sollte Syntax OK enthalten.
The output should contain Syntax OK.
Firewall konfigurieren
Configure the firewall
Falls du UFW (Uncomplicated Firewall) verwendest, musst du Apache durch die Firewall erlauben:
If you are using UFW (Uncomplicated Firewall), you need to allow Apache through the firewall:
sudo ufw allow 'Apache'Für HTTPS-Unterstützung (Port 443) verwende stattdessen:
For HTTPS support (port 443) use instead:
sudo ufw allow 'Apache Full'Überprüfe den Firewall-Status:
Check the firewall status:
sudo ufw status🎉 Fertig! Dein Apache2 Webserver ist jetzt eingerichtet und bereit, deine Website zu hosten. Öffne deinen Browser und rufe http://DEINE-IP auf, um deine Seite zu sehen.
🎉 Done! Your Apache2 web server is now set up and ready to host your website. Open your browser and visit http://YOUR-IP to see your site.