GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come installare Drupal con Nginx e Lets Encrypt SSL su Ubuntu 20.04 LTS

Drupal è un sistema di gestione dei contenuti gratuito e open source che ti aiuta a creare e distribuire contenuti digitali per il Web e i telefoni cellulari. È scritto in PHP e utilizzato da molte organizzazioni in tutto il mondo. Con Drupal puoi creare diversi tipi di siti web, dai piccoli blog ai grandi siti web aziendali. Offre un'interfaccia facile da usare e potenti strumenti di modifica per la gestione dei contenuti.

In questo tutorial, ti mostreremo come installare Drupal con Nginx e proteggerlo con Let's Encrypt SSL su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04.
  • Un nome di dominio valido puntato al tuo server.
  • Sul tuo server è configurata una password di root.

Installa il server LEMP

Innanzitutto, dovrai installare il server web Nginx, il database MariaDB, PHP e altre estensioni richieste sul tuo server. Puoi installarli tutti usando il seguente comando:

apt-get install nginx mariadb-server php7.4 php7.4-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip -y

Una volta installati tutti i pacchetti, modifica il file php.ini e modifica alcune impostazioni:

nano /etc/php/7.4/fpm/php.ini

Modifica le seguenti righe:

short_open_tag = On 
cgi.fix_pathinfo=0
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 300
date.timezone = America/Chicago

Salva e chiudi il file quando hai finito.

Configura il database MariaDB

Per prima cosa, proteggi l'installazione di MariaDB e imposta la password root di MariaDB con il seguente comando:

mysql_secure_installation

Rispondi a tutte le domande come mostrato di seguito:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Una volta che MariaDB è protetto, accedi alla shell MariaDB con il seguente comando:

mysql -u root -p

Fornisci la tua password di root MariaDB, quindi crea un database e un utente per Drupal:

MariaDB [(none)]> CREATE DATABASE drupaldb;
MariaDB [(none)]> CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'password';

Quindi, concedi tutti i privilegi al database Drupal con il seguente comando:

MariaDB [(none)]> GRANT ALL ON drupaldb.* TO 'drupal'@'localhost' WITH GRANT OPTION;

Quindi, svuota i privilegi ed esci dalla shell MariaDB con il seguente comando:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Una volta terminato, puoi procedere al passaggio successivo.

Scarica Drupal

Al momento della stesura di questo tutorial, l'ultima versione di Drupal è 8.8.5. Puoi scaricarlo nella directory principale web di Nginx con il seguente comando:

cd /var/www/html/
wget https://ftp.drupal.org/files/projects/drupal-8.8.5.tar.gz

Una volta completato il download, estrai il file scaricato con il seguente comando:

tar -xvzf drupal-8.8.5.tar.gz

Quindi, rinomina la directory estratta in drupal e dai i permessi appropriati con il seguente comando:

mv drupal-8.8.5 drupal
chown -R www-data:www-data drupal
chmod -R 755 drupal

Una volta terminato, puoi procedere al passaggio successivo.

Configura Nginx per Drupal

Quindi, crea un file di configurazione dell'host virtuale Nginx per drupal usando il seguente comando:

nano /etc/nginx/sites-available/drupal

Aggiungi le seguenti righe:

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/drupal;
    index  index.php index.html index.htm;
    server_name  drupal.linuxbuz.com;

    client_max_body_size 100M;
    autoindex off;

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Block access to scripts in site files directory
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }

    location ~ (^|/)\. {
        return 403;
    }

    location / {
        try_files $uri /index.php?$query_string;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    location ~ '\.php$|^/update.php' {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }
}

Salva e chiudi il file, quindi crea un collegamento simbolico alla directory abilitati ai siti:

ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/

Quindi, imposta hash_bucket_size nel file di configurazione predefinito di Nginx:

nano /etc/nginx/nginx.conf

Aggiungi la seguente riga sotto "http { "

    server_names_hash_bucket_size 64;

Salva e chiudi il file, quindi controlla Nginx per eventuali errori di sintassi:

nginx -t

Dovresti ottenere il seguente output:

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

Quindi, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Una volta terminato, puoi procedere al passaggio successivo.

Proteggi Drupal con Let's Encrypt SSL

Si consiglia di proteggere Drupal con Let's Encrypt SSL. Innanzitutto, aggiungi il repository Certbot con il seguente comando:

add-apt-repository ppa:ahasenack/certbot-tlssni01-1875471

Quindi, aggiorna il repository e installa il client Certbot con il seguente comando:

apt-get update -y
apt-get install certbot python3-certbot-nginx -y

Una volta installato il client Certbot, esegui il seguente comando per scaricare e installare Let's Encrypt SSL per il tuo sito web:

certbot --nginx -d drupal.linuxbuz.com

Ti verrà richiesto di fornire la tua email valida e di accettare i termini del servizio come mostrato di seguito:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y



Obtaining a new certificate
Performing the following challenges:
http-01 challenge for drupal.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/drupal

Quindi, scegli se reindirizzare o meno il traffico HTTP su HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Digita 2 e premi Invio per completare l'installazione:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/drupal

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://drupal.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=drupal.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/drupal.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/drupal.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-08-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

A questo punto, il tuo sito web Drupal è protetto con Let's Encrypt SSL.

Accedi alla procedura guidata di installazione di Drupal Web

Ora apri il tuo browser web e digita l'URL https://drupal.linuxbuz.com. Verrai reindirizzato alla pagina di selezione della lingua di Drupal:

Seleziona la lingua desiderata e fai clic su Salva e continua pulsante. Dovresti vedere la pagina del profilo di installazione:

Seleziona il profilo di installazione desiderato e fai clic su Salva e continua pulsante. Dovresti vedere la pagina di configurazione del database:

Fai clic su Salva e continua pulsante. Dovresti vedere la pagina di configurazione del sito:

Fornisci il nome del sito, il nome utente dell'amministratore, la password e fai clic su Salva e continua pulsante. Verrai reindirizzato alla dashboard predefinita di Drupal nella pagina seguente:

Conclusione

Congratulazioni! hai installato e protetto con successo Drupal con Let's Encrypt SSL su Ubuntu 20.04. Ora puoi iniziare a personalizzare il tuo sito web Drupal. Per ulteriori informazioni, visita la documentazione ufficiale di Drupal.


Ubuntu
  1. Come installare Nextcloud con Nginx e Lets Encrypt SSL su Ubuntu 20.04 LTS

  2. Come installare Magento 2 con Nginx e Lets Encrypt SSL su Ubuntu 20.04 LTS

  3. Come installare Seafile con Nginx su Ubuntu 20.04 LTS

  4. Come installare Drupal 8 con Nginx, PHP-FPM e SSL su Ubuntu 15.10

  5. Come installare Drupal 8.1 con Nginx, PHP-FPM e SSL su Ubuntu 16.04

Come installare NodeBB Forum con Nginx e Lets Encrypt SSL su Ubuntu 20.04 LTS

Come installare Moodle con Nginx e Lets Encrypt SSL su Ubuntu 20.04

Come installare MediaWiki con Nginx e Lets Encrypt SSL su Ubuntu 20.04

Come installare Gitea con Nginx e Lets Encrypt SSL gratuito su Ubuntu 20.04

Come installare Let's Encrypt SSL con Nginx su Ubuntu 16.04 LTS

Come installare Nginx con Let's Encrypt SSL su Ubuntu 20.04 LTS