GNU/Linux >> Linux Esercitazione >  >> Panels >> Panels

Come installare LEMP su Ubuntu 16.04

Ti mostreremo come installare LEMP su Ubuntu 16.04. Stack LEMP (Linux, Nginx , MySQL, PHP) non deve essere confuso con il popolare stack LAMP (Linux, Apache , MySQL, PHP) . Questo tutorial è per lo stack LEMP (Nginx) ed è comunemente usato sui server Ubuntu 16.04. L'installazione di LEMP su Ubuntu 16.04 non dovrebbe richiedere più di 10 min. Iniziamo con l'installazione di LEMP su Ubuntu 16.04:

1. Aggiorna il server

Assicurati che tutti i pacchetti installati sul tuo VPS Ubuntu 16.04 siano aggiornati.

apt-get update && apt-get upgrade

Puoi anche configurare gli aggiornamenti automatici.

2. Installa Nginx su Ubuntu 16.04

Prima di installare il server web Nginx, assicurati che non ci siano altri server web come Apache installati sul VPS. Se il server Web Apache è in esecuzione, arrestarlo:

systemctl stop apache2

e rimuovilo dal tuo VPS:

apt-get remove --purge apache2

Ora, esegui il seguente comando per installare Nginx:

apt-get install nginx

3. Avvia Nginx

Una volta installato, avvia il server web e abilitalo all'avvio all'avvio:

systemctl start nginx
systemctl enable nginx

Puoi verificare se Nginx è stato avviato correttamente utilizzando il seguente comando:

systemctl status nginx

L'output del comando precedente dovrebbe essere simile a questo:

   nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running)
   Main PID: 5926 (nginx)
   CGroup: /system.slice/nginx.service
           ├─5926 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           ├─5927 nginx: worker process
           └─5928 nginx: worker process

Puoi anche verificare se Nginx è in esecuzione, accedendo a http://YOUR_IP nel tuo browser web preferito.

4. Installa PHP-FPM

Esegui i seguenti comandi per installare i pacchetti PHP necessari:

apt-get install php-fpm php-mysql

5. Configura PHP-FPM

Una volta completata l'installazione, modifica il file di configurazione PHP e modifica il cgi.fix_pathinfo valore del parametro da 1 a 0.

Per trovare la posizione del file php.ini esegui il seguente comando:

php --ini |grep Loaded
Loaded Configuration File:         /etc/php/7.0/cli/php.ini

Dobbiamo modificare il file /etc/php/7.0/cli/php.ini e apportare le modifiche.

vi /etc/php/7.0/cli/php.ini

cgi.fix_pathinfo=0

Salva le modifiche e riavvia PHP-FPM:

systemctl restart php7.0-fpm

6. Configura il server Web Nginx

Il prossimo passo è configurare Nginx per usare PHP. Modificheremo il blocco del server Nginx predefinito e aggiungeremo/deleveremo il location ~\.php$ blocco.

vi /etc/nginx/sites-available/default

server {
        listen 80 default_server;
        
       root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}

Salva le modifiche e prova la nuova configurazione

nginx -t 

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

7. Riavvia il server Web Nginx

Se non ci sono errori, riavvia il server web

systemctl restart nginx

8. Installa il server MySQL

Installa il server di database MySQL eseguendo il comando seguente:

apt-get install mysql-server

Durante l'installazione, ti verrà chiesto di inserire una password per l'utente root di MySQL. Assicurati di utilizzare una password complessa (combinazione di lettere e numeri e di almeno 10 caratteri) per il tuo utente root.

9. Proteggi il server MySQl

Una volta completata l'installazione del server MySQL, si consiglia di proteggere l'installazione eseguendo lo script di sicurezza fornito da MySQL:

mysql_secure_installation

e segui i consigli.

10. Avvia MySql Server

Avvia MySQL e abilitalo all'avvio all'avvio

systemctl start mysql
systemctl enable mysql

E questo è tutto. Hai installato con successo lo stack LEMP sul tuo server Ubuntu 16.04.

Ulteriori passaggi:

Dopo aver installato lo stack LEMP, puoi seguire la nostra guida su come proteggerlo: Come proteggere lo stack LEMP

Ovviamente, non devi installare LEMP su Ubuntu 16.04, se utilizzi uno dei nostri servizi di hosting LEMP, nel qual caso puoi semplicemente chiedere ai nostri esperti amministratori Linux di installare LEMP su Ubuntu 16.04, per te. Sono disponibili 24 ore su 24, 7 giorni su 7 e si prenderanno immediatamente cura della tua richiesta.

PS. Se ti è piaciuto questo post su come installare LEMP su Ubuntu 16.04, condividilo con i tuoi amici sui social network usando i pulsanti qui sotto o lascia semplicemente una risposta nella sezione commenti. Grazie.


Panels
  1. Come installare FastPanel su Ubuntu 20.04

  2. Come installare MySQL su Ubuntu 16.04

  3. Come installare Graylog Server su Ubuntu 16.04

  4. Come installare Nginx su Ubuntu 18.04

  5. Come installare LEMP su Ubuntu 18.04

Come installare Nginx Web Server su Ubuntu 20.04

Come installare aaPanel su Ubuntu 20.04

Come installare Nginx su Ubuntu 14.04

Come installare Nginx, MySQL e PHP (LEMP) su un server Ubuntu 15.04

Come installare NGINX su Ubuntu 20.04

Come installare NGINX su Ubuntu 18.04