Der LAMP-Stack (Linux, Apache, MariaDB / MySQL und PHP) ist der am weitesten verbreitete Software-Technologie-Stack, der von Hosting-Unternehmen zum Hosten von Websites und Blogs verwendet wird. Darüber hinaus wird dieser Stack häufig zum Bereitstellen von Content-Management-Systemen wie WordPress, Drupal, Joomla usw. verwendet.
Hier sehen wir, wie man den LAMP-Stack auf Ubuntu 20.04 installiert.
AMP-Stack installieren
In Ubuntu können Sie den AMP-Stack manuell installieren, indem Sie Apache, MariaDB und PHP einzeln oder den gesamten Stack mit einem einzigen Befehl installieren.
Bei der Installation von AMP Stack mit einem einzigen Befehl wird MySQL v8.0 installiert. Wenn Sie sich jedoch gleichzeitig für die manuelle Installation des LAMP-Stacks entscheiden, erhalten Sie MariaDB v10.6.Methode 1:LAMP Stack manuell installieren (eins nach dem anderen)
Wir werden AMP (Apache v2.4, PHP v8.1 und MariaDB v10.6) auf Ubuntu 20.04 installieren.
Apache installieren
Aktualisieren Sie zuerst den Paket-Repository-Index.
sudo apt update
Installieren Sie dann das Apache2-Paket mit apt
Befehl.
sudo apt install -y apache2 apache2-utils
Installieren Sie MariaDB
MariaDB hat MySQL als Standard-Datenbankserver in Ubuntu ersetzt und ist im Ubuntu-Repository verfügbar (v10.6).
Sie können auch die neueste Version von MariaDB aus dem MariaDB-Repository installieren.
sudo apt install -y mariadb-server mariadb-client
Führen Sie dann mysql_secure_installation
aus Befehl zum Sichern der MySQL-Installation.
sudo mysql_secure_installation
Ausgabe:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): << Just Press Enter OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] N << Disable Unix Socket Authentication ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] Y << Set MariaDB root password New password: xxx << Enter new MariaDB root password Re-enter new password: xxx << Re-enter new MariaDB root password Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y << Remove Anonymous Users ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y << Disallow root login remotely ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y << Remove test database - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y << Reload privilege tables ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Installieren Sie PHP
Standardmäßig unterstützt der Apache-Server nur die Bereitstellung statischer HTML-Dateien, nicht PHP. Daher müssen Sie PHP und das PHP-Erweiterungspaket für MariaDB/MySQL installieren, falls erforderlich, um die PHP-Unterstützung zu aktivieren.
Ubuntu 22.04 kommt mit PHP v8.1.
sudo apt install -y php php-mysql libapache2-mod-php
Starten Sie nach der Installation den Apache-Webserver neu.
sudo systemctl restart apache2
Jetzt können Sie zum Testen des LAMP-Stacks gehen.
Methode 2:Installieren Sie den LAMP-Stack in einem einzigen Befehl
Wir werden AMP (Apache v2.4, PHP v8.1 und MySQL v8.0) auf Ubuntu 20.04 installieren.
Aktualisieren Sie den Repository-Cache mit dem apt-Befehl.
sudo apt update
Fügen Sie unterhalb der Zeile im Terminal ein und drücken Sie die Eingabetaste.
sudo apt install -y lamp-server^
Der obige Befehl sucht und installiert die erforderlichen Pakete für den LAMP-Server. Sie müssen einige Minuten warten, bis die Installation des LAMP-Stacks abgeschlossen ist.
Führen Sie die mysql_secure_installation
aus Befehl zum Sichern der MySQL-Installation.
sudo mysql_secure_installation
Ausgabe:
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y << Enable validate password component to validate the strength of user passwords There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 << Level of password validation policy Please set the password for root here. New password: xxx << Set MySQL root password Re-enter new password: xxx << Re-Enter MySQL root password Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y << Continue By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y << Remove anonymous users Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y << Disable root login remotely Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y << Remove test database - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y << Reload tables Success. All done!MySQL verwendet den Unix-Socket-Authentifizierungsmechanismus für MySQL-Root-Benutzer, wenn es aus dem Ubuntu-Repository installiert wird. Dieser Authentifizierungsmechanismus erlaubt MySQL-Root-Benutzern, sich nur über den Unix-Socket anzumelden (#-Eingabeaufforderung oder sudo).
Führen Sie die folgenden Schritte aus, um die Unix-Socket-Authentifizierung zu deaktivieren und den nativen Passwortmechanismus zu aktivieren.
Melden Sie sich als MariaDB-Root-Benutzer an.
sudo mysql -u root -p
Kein Passwort erforderlich
use mysql; update user set plugin='mysql_native_password' where user='root'; flush privileges; quit;
LAMP-Stack testen
Der Standard-Dokumentenstamm von Apache ist /var/www/html
und die Hauptkonfigurationsdatei ist /etc/apache2/apache2.conf
. Weitere Konfigurationen wie virtuelle Hosts und Module finden Sie in /etc/apache2/*-enabled
Verzeichnis.
Zum Testen von PHP platzieren wir eine PHP-Datei im Standard-Dokumentenstammverzeichnis von Apache.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Öffnen Sie nun einen Webbrowser und geben Sie Folgendes in die Webadresse ein, um auf die Testseite zuzugreifen:
http://ip.ad.dr.ess/info.phpDie Seite sieht wie folgt aus.
Scrollen Sie die Seite nach unten, um die Details der PHP-Erweiterungen für MySQL/MariaDB anzuzeigen.
Schlussfolgerung
Das ist alles. Ich hoffe, Sie haben inzwischen einen LAMP-Stack auf Ubuntu 20.04. Bitte teilen Sie uns Ihr Feedback im Kommentarbereich mit.