Stack LEMP sta per stack Linux, Nginx, MariaDB e PHP. È uno stack tecnologico ampiamente utilizzato per ospitare siti Web e blog.
Questo tutorial mostra come installare Nginx con supporto PHP (tramite PHP-FPM) e supporto MySQL su Ubuntu 16.04.
Installa lo stack LEMP
Installa Nginx
Scarica la chiave di firma dal sito Web ufficiale.
wget http://nginx.org/keys/nginx_signing.key
Aggiungilo per evitare avvisi durante l'installazione di nginx.
sudo apt-key add nginx_signing.key
Aggiungi il repository Nginx inserendo le seguenti informazioni.
echo "deb http://nginx.org/packages/mainline/ubuntu xenial nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
Aggiorna i repository.
sudo apt-get update
Installa Nginx usando il seguente comando.
sudo apt-get install -y nginx
Avvia il servizio Nginx dopo l'installazione.
sudo systemctl start nginx
Apri un browser web e visita http://il-tuo-indirizzo-ip.
Dovresti vedere la seguente pagina e questa pagina conferma che Nginx è stato installato correttamente sul server.

La radice del documento nginx predefinita su Ubuntu 16.04 è /usr/share/nginx/html/. I file di configurazione si trovano nella directory /etc/nginx.
Installa MariaDB
Ubuntu 16.04 fornisce MariaDB v10.0 che è già la fine della vita. Quindi, installeremo MariaDB v10.4 dal repository ufficiale.
Aggiungi il repository MariaDB sul tuo sistema.
sudo apt-get install -y software-properties-common sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 sudo add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu xenial main' sudo apt-get update
Installa MariaDB usando il comando seguente.
sudo apt-get install -y mariadb-server mariadb-client
Quindi, proteggi l'installazione di MariaDB con il comando mysql_secure_installation.
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): << No Password - 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 << Disabling Unix Socket login and enabling password Login ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] Y << Change MariaDB root password New password: << Enter Password Re-enter new password: << Re-Enter 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 ... 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
Successivamente è installare PHP tramite PHP-FPM (PHP-FPM (FastCGI Process Manager), è un'implementazione PHP FastCGI alternativa. ha alcune funzionalità aggiuntive utili per siti di qualsiasi dimensione, in particolare quelli più frequentati).
Ubuntu 16.04 fornisce PHP-FPM v7.0 che è già la fine della vita. Quindi, installeremo PHP-FPM v7.3 dal repository Ondřej Surý.
LEGGI: Come installare PHP 7.3/7.2/7.1 su Ubuntu 16.04
Aggiungi il repository.
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Installa PHP-FPM v7.3 utilizzando il comando seguente.
sudo apt-get install -y php7.3-fpm php7.3-mysql php7.3-cli
Modifica il file seguente per configurare PHP-FPM per utilizzare la connessione TCP invece del socket Unix.
sudo nano /etc/php/7.3/fpm/pool.d/www.conf
Modifica il parametro di ascolto mostrato come di seguito.
listen = 127.0.0.1:9000
Test stack LAMPADE
Creiamo un host virtuale basato sul nome sul server Nginx per i seguenti dettagli.
Nome server: server.itzgeek.local
Radice del documento: /usr/share/nginx/html/server.itzgeek.local
Crea il file di configurazione chiamato virtual.conf nella directory /etc/nginx/conf.d/.
sudo nano /etc/nginx/conf.d/virtual.conf
Aggiungi il seguente contenuto.
server { server_name server.itzgeek.local; root /usr/share/nginx/html/server.itzgeek.local; location / { index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
Crea la directory principale del documento.
sudo mkdir -p /usr/share/nginx/html/server.itzgeek.local
Per testare il PHP, posiziona un file PHP nella radice del documento dell'host virtuale creato.
Nel terminale copia/incolla la seguente riga:
echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/server.itzgeek.local/index.php
Riavvia i servizi.
sudo systemctl restart nginx sudo systemctl restart php7.3-fpm
Nel tuo sistema client, crea una voce host per il tuo dominio (server.itzgeek.local) nel file /etc/hosts nel caso in cui il tuo ambiente non disponga di un server DNS.
sudo nano /etc/hosts
La voce dell'ospite piacerà di seguito
192.168.1.10 server.itzgeek.local
Ora apri il tuo browser web e digita il tuo dominio nell'indirizzo web:
http://server.itzgeek.localLa pagina apparirà come di seguito:
Dallo screenshot sopra, PHP funziona e funziona tramite FPM/FastCGI, come mostrato nella riga Server API.

Se scorri più in basso, vedrai tutti i moduli abilitati in PHP. L'immagine sottostante mostra le informazioni sul modulo MySQL.

Conclusione
È tutto. Spero che tu abbia imparato come installare LEMP Stack su Ubuntu 16.04. Prendi in considerazione la configurazione del certificato Let's Encrypt per il tuo dominio per migliorare la sicurezza. Condividi il tuo feedback nella sezione commenti.