Installation des LAMP Stack mit Apache, MariaDB und PHP
-
Update des Systems
1sudo apt update -y -
Installation Webserver Apache2
- Installation des Apache Webservers mit
1sudo apt install -y apache2 apache2-utils
- Prüfe Apache2 Service mit
1systemctl status apache2
- Apache2 automatisch beim Booten starten lassen mit
1sudo systemctl enable apache2
- Wenn IPTables verwendet werden, den Zugriff auf TCP Port 80 zulassen mit
1sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
- Wenn IPTables verwendet werden, den Zugriff auf TCP Port 443 zulassen mit
1sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
- Prüfung der Übernahme mit
1sudo iptables -L
- bei Verwendung von UFW, den Zugriff auf TCP Port 80 UND 443 gewähren mit
1sudo ufw allow in "Apache Full"
- bei Verwendung von UFW, den Zugriff auf TCP Port 80 gewähren mit
1sudo ufw allow in "Apache"
- bei Verwendung von UFW, den Zugriff auf TCP Port 443 gewähren mit
1sudo ufw allow in "Apache Secure"
- Übernahme der Regeln mit
1sudo ufw reload
- anschließende Prüfung des UFW Status mit
1sudo ufw status
- Zugriff auf den Webroot dem Apache User gewähren mit
1sudo chown www-data:www-data /var/www/html/ -R
- Falls ein Problem mit der Auflösung des lokalen Servernamen und Apache auftritt, kann man dies lösen, indem man in der Apache Konfiguration den „Globalen Servernamen“ localhost hinzufügt. Das geschieht mit
1sudo nano /etc/apache2/conf-available/servername.conf
und dem hinzufügen der Zeile
1ServerName localhost - Weitere Steuerbefehle…
- Starte Apache2 Service mit
1sudo systemctl start apache2
- Stoppe Apache2 Service mit
1sudo systemctl stop apache2
- Naustart Apache2 Service mit
1sudo systemctl restart apache2
- Prüfe Apache2 Version mit
1apache2 -v
- Installation des Apache Webservers mit
-
Installation Datenbakserver MariaDB
- Installation MariaDB mit
1sudo apt install mariadb-server mariadb-client -y
- Aktiviere automatischen Start des MariaDB Service mit
1sudo systemctl enable mariadb
- Starte MariaDB Service mit
1sudo systemctl start mariadb - Stoppe MariaDB Service mit
1sudo systemctl stop mariadb - Neustart MariaDB Service mit
1sudo systemctl restart mariadb - Prüfe Status MariaDB Service mit
1systemctl status mariadb - Abfrage der Version mit
1mariadb --version - Der Start des Script erfolgt mit
1sudo mysql_secure_installation - Wizard komplett abschließen, alle Antworten im Regelfall default belassen…
1Change the root password? [Y/n] n
…
1Remove anonymous users? [Y/n] y
…
1Disallow root login remotely? [Y/n] y
…
1Remove test database and access to it? [Y/n] y
…
1Reload privilege tables now? [Y/n] y - Der Start des MariaDB Clients, zur Anlage von DB’s etc. erfolgt dann mit
1sudo mariadb -u root
Weitere Steuerbefehle:
MariaDB Post Installation Script:
- Installation MariaDB mit
-
Installation PHP Interpreter
- PHP (aktuell v 7.4) und häufig benötigte Module installieren mit
1sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline -y - Apache php Modul aktivieren mit
1sudo a2enmod php7.4 - Apache Webserver neu starten mit
1sudo systemctl restart apache2 - Prüfung der PHP Version mit
1php --version - Um die Funktion von PHP sicherzustellen, erstellen wir eine Info Datei mit
1sudo nano /var/www/html/info.php - Im Editor folgende Zeile hinzufügen
1<?php phpinfo(); ?> - Browser öffnen und die URL http://IP_deines_Servers/info.php öffnen
- PHP (aktuell v 7.4) und häufig benötigte Module installieren mit
-
HTTPS mit Self Signed Zertifikat aktivieren
- Aktivieren des Apache SSL Modul mit
1sudo a2enmod ssl
- Restart Apache2 Service mit
1sudo systemctl restart apache2
- Erstellen des Zertifikates mit
1sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
-
1234567Country Name (2 letter code) [XX]:DEState or Province Name (full name) []:BundeslandLocality Name (eg, city) [Default City]:StadtOrganization Name (eg, company) [Default Company Ltd]:FirmennameOrganizational Unit Name (eg, section) []:AbteilungCommon Name (eg, your name or your server's hostname) []:servername.domain.netEmail Address []:webmaster@domain.net