GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Installa LAMP Stack (Apache, MariaDB, PHP) su Ubuntu 22.04

Lo stack LAMP (Linux, Apache, MariaDB/MySQL e PHP) è lo stack di tecnologia software più utilizzato dalle società di hosting per ospitare siti Web e blog. Inoltre, questo stack viene comunemente utilizzato per distribuire sistemi di gestione dei contenuti come WordPress, Drupal, Joomla, ecc.

Qui vedremo come installare lo stack LAMP su Ubuntu 20.04.

Installa lo stack AMP

In Ubuntu, puoi installare manualmente lo stack AMP installando Apache, MariaDB e PHP uno per uno o l'intero stack con un solo comando.

Quando si installa AMP Stack utilizzando un singolo comando, verrà installato MySQL v8.0. Ma, allo stesso tempo, se scegli di installare manualmente lo stack LAMP, otterrai MariaDB v10.6.

Metodo 1:installa lo stack LAMP manualmente (uno per uno)

Installeremo AMP (Apache v2.4, PHP v8.1 e MariaDB v10.6) su Ubuntu 20.04.

Installa Apache

Innanzitutto, aggiorna l'indice del repository del pacchetto.

sudo apt update

Quindi, installa il pacchetto apache2 usando apt comando.

sudo apt install -y apache2 apache2-utils

Installa MariaDB

MariaDB ha sostituito MySQL come server di database predefinito in Ubuntu ed è disponibile (v10.6) dal repository di Ubuntu.

Puoi anche installare l'ultima versione di MariaDB dal repository di MariaDB.

sudo apt install -y mariadb-server mariadb-client

Quindi, esegui mysql_secure_installation comando per proteggere l'installazione di MySQL.

sudo mysql_secure_installation

Risultato:

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!

Installa PHP

Per impostazione predefinita, il server Apache supporta solo la pubblicazione di file HTML statici, non PHP. Pertanto, per abilitare il supporto PHP, dovrai installare PHP e il pacchetto di estensione PHP per MariaDB/MySQL, se necessario.

Ubuntu 22.04 viene fornito con PHP v8.1.

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

Dopo l'installazione, riavvia il server web Apache.

sudo systemctl restart apache2

Ora puoi andare a Test dello stack LAMP.

Metodo 2:installa lo stack LAMP in un comando singolo

Installeremo AMP (Apache v2.4, PHP v8.1 e MySQL v8.0) su Ubuntu 20.04.

Aggiorna la cache del repository usando il comando apt.

sudo apt update

Incolla sotto la riga nel terminale e premi invio.

sudo apt install -y lamp-server^

Il comando precedente cercherà e installerà i pacchetti richiesti per il server LAMP. Dovrai attendere alcuni minuti per completare l'installazione dello stack LAMP.

Esegui mysql_secure_installation comando per proteggere l'installazione di MySQL.

sudo mysql_secure_installation

Risultato:

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 utilizza il meccanismo di autenticazione Unix Socket per l'utente root MySQL quando installato dal repository Ubuntu. Questo meccanismo di autenticazione consente all'utente root di MySQL di accedere solo dal socket Unix (# prompt o sudo).

Per disabilitare l'autenticazione di Unix Socket e abilitare il meccanismo della password nativa, segui i passaggi seguenti.

Accedi come utente root di MariaDB.

sudo mysql -u root -p

Nessuna password richiesta

use mysql;

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

flush privileges;

quit;

Test stack LAMPADE

La radice del documento predefinita di Apache è /var/www/html e il file di configurazione principale è /etc/apache2/apache2.conf . Puoi trovare configurazioni aggiuntive come host virtuali e moduli in /etc/apache2/*-enabled directory.

Per testare il PHP, collocheremo un file PHP nella root del documento predefinita di Apache.

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

Ora apri un browser web e digita quanto segue nell'indirizzo web per accedere alla pagina di test:

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

La pagina sarà simile alla seguente.

Scorri la pagina verso il basso per vedere i dettagli delle estensioni PHP per MySQL/MariaDB.

Conclusione

È tutto. Spero che ormai tu abbia lo stack LAMP su Ubuntu 20.04. Condividi il tuo feedback nella sezione commenti.


Ubuntu
  1. Come installare lo stack LAMP su Ubuntu 18.04

  2. Come installare WordPress su Ubuntu 18.04 utilizzando lo stack LAMP

  3. Come installare lo stack Linux, Apache, MySQL, PHP (LAMP) su Ubuntu 16.04

  4. Installa WordPress con Stack LAMP su Ubuntu 20.04

  5. Come installare e configurare PHP e Apache (stack LAMP) su Ubuntu 20.04

Come installare lo stack LAMP (Apache, MariaDB, PHP7.1) su Ubuntu 17.10

Come installare lo stack LAMP su Ubuntu 20.04 Server/Desktop

Come installare Apache, MySQL, PHP (stack LAMP) su Ubuntu

Come installare lo stack LAMP su Ubuntu 20.04

Come installare uno stack LAMP (Apache, MariaDB, PHP) su CentOS 7

Come installare lo stack Apache, MySQL, PHP (LAMP) su Ubuntu 16.04