Drupal met Nginx en Let’s Encrypt SSL op Ubuntu 20.04 LTS te installeren

Drupal is een gratis en open-source inhoudbeheersysteem dat je helpt digitale inhoud voor het web en mobiele telefoons te maken en af te leveren. Het is geschreven in PHP en wordt door veel organisaties over de hele wereld gebruikt. Met Drupal kun je verschillende soorten websites maken, van kleine blogs tot een grote bedrijfswebsite. Het biedt een gemakkelijk te gebruiken interface en krachtige bewerkingsgereedschappen om inhoud te beheren.

In deze handleiding laten we je zien hoe je Drupal met Nginx installeert en met Let’s Encrypt SSL beveiligt op Ubuntu 20.04.

Vereisten

  • Een server met Ubuntu 20.04.
  • Een geldige domeinnaam die met je server is verbonden.
  • Een root wachtwoord is op je server ingesteld.

Installeer de LEMP server

Eerst moet je de Nginx webserver, de MariaDB databank, PHP en andere vereiste uitbreidingen op je server installeren. Je kunt ze allemaal installeren met het volgende commando:

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

Als alle pakketten geïnstalleerd zijn, bewerk je het php.ini bestand en pas je enkele instellingen aan:

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

Verander de volgende regels:

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

Sla het bestand op en sluit het als je klaar bent.

Configureer de MariaDB Database

Beveilig eerst de MariaDB installatie en stel het MariaDB root wachtwoord in met het volgende commando:

mysql_secure_installation

Beantwoord alle vragen zoals hieronder aangegeven:

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

Zodra de MariaDB beveiligd is, log je in op de MariaDB shell met het volgende commando:

mysql -u root -p

Geef je MariaDB root wachtwoord en maak dan een database en gebruiker voor Drupal:

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

Verleen vervolgens alle rechten aan de Drupal database met het volgende commando:

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

Spoel vervolgens de privileges door en verlaat de MariaDB shell met het volgende commando:

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

Als je klaar bent, kun je verder gaan met de volgende stap.

Drupal downloaden

Op het moment van schrijven van deze handleiding is de nieuwste versie van Drupal 8.8.5. Je kunt het downloaden naar de Nginx web root directory met het volgende commando:

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

Als de download voltooid is, pak je het gedownloade bestand uit met het volgende commando:

tar -xvzf drupal-8.8.5.tar.gz

Hernoem vervolgens de uitgepakte directory naar drupal en geef de juiste rechten met het volgende commando:

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

Als je klaar bent, kun je verder gaan met de volgende stap.

Configureer Nginx voor Drupal

Maak vervolgens een Nginx virtual host configuratiebestand voor drupal met het volgende commando:

nano /etc/nginx/sites-available/drupal

Voeg de volgende regels toe:

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;
    }
}

Bewaar en sluit het bestand en maak dan een symbolische link naar de directory sites-enabled:

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

Stel vervolgens hash_bucket_size in Nginx standaard configuratiebestand in:

nano /etc/nginx/nginx.conf

Voeg de volgende regel toe onder“http {

    server_names_hash_bucket_size 64;

Bewaar en sluit het bestand en controleer Nginx dan op een syntaxisfout:

nginx -t

Je zou de volgende uitvoer moeten krijgen:

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

Herstart vervolgens de Nginx dienst om de veranderingen toe te passen:

systemctl restart nginx

Als je klaar bent, kun je verder gaan met de volgende stap.

Beveilig Drupal met Let’s Encrypt SSL

Het is aan te bevelen om Drupal met Let’s Encrypt SSL te beveiligen. Voeg eerst de Certbot repository toe met het volgende commando:

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

Werk vervolgens de repository bij en installeer de Certbot client met het volgende commando:

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

Als de Certbot client geïnstalleerd is, voer je het volgende commando uit om Let’s Encrypt SSL voor je website te downloaden en te installeren:

certbot --nginx -d drupal.linuxbuz.com

Je wordt gevraagd je geldige e-mail op te geven en de servicevoorwaarden te accepteren, zoals hieronder:

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

Kies vervolgens of je HTTP verkeer al dan niet wilt omleiden naar 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

Type 2 en druk op Enter om de installatie te voltooien:

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

Op dit punt is je Drupal website beveiligd met Let’s Encrypt SSL.

Ga naar de Drupal web installatie wizard

Open nu je web browser en typ de URL https://drupal.linuxbuz.com. Je wordt doorverwezen naar de Drupal taalkeuze pagina:

Drupal installatieprogramma - Kies taal

Kies de gewenste taal en klik op de knop Opslaan en doorgaan. Je zou nu de Installatie profiel pagina moeten zien:

Kies installatieprofiel

Kies je gewenste installatieprofiel en klik op de knop Opslaan en doorgaan. Je zou de Database configuratie pagina moeten zien:

Database configuratie

Klik op de knop Opslaan en doorgaan. Je zou de Site configuratie pagina moeten zien:

Drupal site configuratie

Regionale instellingen

Geef je sitenaam, admin gebruikersnaam, wachtwoord en klik op de bewaar en ga verder knop. Je wordt doorgestuurd naar het Drupal standaard dashboard op de volgende pagina:

Drupal succesvol geïnstalleerd

Conclusie

Gefeliciteerd! Je hebt Drupal met succes geïnstalleerd en beveiligd met Let’s Encrypt SSL op Ubuntu 20.04. Je kunt nu beginnen met het aanpassen van je Drupal website. Meer informatie vind je in de officiële Drupal documentatie.