GNU/Linux >> Tutoriels Linux >  >> Ubuntu

Installer LAMP Stack (Apache, MariaDB, PHP) sur Ubuntu 22.04

La pile LAMP ( Linux, Apache, MariaDB / MySQL et PHP) est la pile technologique logicielle la plus largement utilisée par les sociétés d'hébergement pour héberger des sites Web et des blogs. De plus, cette pile est couramment utilisée pour déployer des systèmes de gestion de contenu tels que WordPress, Drupal, Joomla, etc.

Ici, nous verrons comment installer la pile LAMP sur Ubuntu 20.04.

Installer la pile AMP

Dans Ubuntu, vous pouvez installer la pile AMP manuellement en installant Apache, MariaDB et PHP un par un ou toute la pile avec une seule commande.

Lors de l'installation d'AMP Stack à l'aide d'une seule commande, il installera MySQL v8.0. Mais, en même temps, si vous choisissez d'installer la pile LAMP manuellement, vous obtiendrez MariaDB v10.6.

Méthode 1 :Installer la pile LAMP manuellement (une par une)

Nous allons installer AMP (Apache v2.4, PHP v8.1 et MariaDB v10.6) sur Ubuntu 20.04.

Installer Apache

Tout d'abord, mettez à jour l'index du référentiel de packages.

sudo apt update

Ensuite, installez le package apache2 en utilisant le apt commande.

sudo apt install -y apache2 apache2-utils

Installer MariaDB

MariaDB a remplacé MySQL comme serveur de base de données par défaut dans Ubuntu, et il est disponible (v10.6) à partir du référentiel Ubuntu.

Vous pouvez également installer la dernière version de MariaDB à partir du référentiel MariaDB.

sudo apt install -y mariadb-server mariadb-client

Ensuite, exécutez le mysql_secure_installation commande pour sécuriser l'installation de MySQL.

sudo mysql_secure_installation

Sortie :

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!

Installer PHP

Par défaut, le serveur Apache ne prend en charge que les fichiers HTML statiques, pas PHP. Par conséquent, vous devrez installer PHP et le package d'extension PHP pour MariaDB/MySQL si nécessaire pour activer la prise en charge de PHP.

Ubuntu 22.04 est livré avec PHP v8.1.

sudo apt install -y php php-mysql libapache2-mod-php

Après l'installation, redémarrez le serveur Web Apache.

sudo systemctl restart apache2

Maintenant, vous pouvez vous diriger vers Tester la pile LAMP.

Méthode 2 :Installer la pile LAMP en une seule commande

Nous allons installer AMP (Apache v2.4, PHP v8.1 et MySQL v8.0) sur Ubuntu 20.04.

Mettez à jour le cache du référentiel à l'aide de la commande apt.

sudo apt update

Collez sous la ligne dans le terminal et appuyez sur Entrée.

sudo apt install -y lamp-server^

La commande ci-dessus recherchera et installera les packages requis pour le serveur LAMP. Vous devrez attendre quelques minutes pour terminer l'installation de la pile LAMP.

Exécutez le mysql_secure_installation commande pour sécuriser l'installation de MySQL.

sudo mysql_secure_installation

Sortie :

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 utilise le mécanisme d'authentification Unix Socket pour l'utilisateur racine MySQL lorsqu'il est installé à partir du référentiel Ubuntu. Ce mécanisme d'authentification permet à l'utilisateur root de MySQL de se connecter uniquement à partir du socket Unix (# prompt ou sudo).

Pour désactiver l'authentification Unix Socket et activer le mécanisme de mot de passe natif, suivez les étapes ci-dessous.

Connectez-vous en tant qu'utilisateur racine MariaDB.

sudo mysql -u root -p

Aucun mot de passe requis

use mysql;

update user set plugin='mysql_native_password' where user='root';

flush privileges;

quit;

Tester la pile LAMP

La racine de document par défaut d'Apache est /var/www/html et le fichier de configuration principal est /etc/apache2/apache2.conf . Vous pouvez trouver des configurations supplémentaires comme des hôtes virtuels et des modules dans le /etc/apache2/*-enabled répertoire.

Pour tester le PHP, nous placerons un fichier PHP sur la racine du document par défaut d'Apache.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Ouvrez maintenant un navigateur Web et saisissez ce qui suit dans l'adresse Web pour accéder à la page de test :

http://ip.ad.dr.ess/info.php

La page ressemblera à celle ci-dessous.

Faites défiler la page vers le bas pour voir les détails des extensions PHP pour MySQL/MariaDB.

Conclusion

C'est tout. J'espère que vous avez maintenant la pile LAMP sur Ubuntu 20.04. Veuillez partager vos commentaires dans la section des commentaires.


Ubuntu
  1. Comment installer la pile LAMP sur Ubuntu 18.04

  2. Comment installer WordPress sur Ubuntu 18.04 à l'aide de LAMP Stack

  3. Comment installer la pile Linux, Apache, MySQL, PHP (LAMP) sur Ubuntu 16.04

  4. Installer WordPress avec LAMP Stack sur Ubuntu 20.04

  5. Comment installer et configurer PHP et Apache (pile LAMP) sur Ubuntu 20.04

Comment installer LAMP Stack (Apache, MariaDB, PHP7.1) sur Ubuntu 17.10

Comment installer LAMP Stack sur le serveur/bureau Ubuntu 20.04

Comment installer Apache, MySQL, PHP (pile LAMP) sur Ubuntu

Comment installer la pile LAMP sur Ubuntu 20.04

Comment installer une pile LAMP (Apache, MariaDB, PHP) sur CentOS 7

Comment installer la pile Apache, MySQL, PHP (LAMP) sur Ubuntu 16.04