Ricerca nel sito web

Come installare Moodle con Nginx e Free Lets Encrypt SSL su Ubuntu 22.04


Questo tutorial esiste per queste versioni del sistema operativo

  • Ubuntu 22.04 (Jammy Jellyfish)
  • Ubuntu 16.04 (Xenial Xerus)

Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa Nginx, MariaDB e PHP
  4. Crea un database per Moodle
  5. Installa Moodle su Ubuntu 22.04
  6. Configura Nginx per Moodle
  7. Accedi all'interfaccia web di Moodle
  8. Proteggi Moodle con Lets Encrypt SSL
  9. Conclusione

Moodle è un sistema di gestione dell'apprendimento gratuito e open source e un CMS scritto in PHP. Consente a tutor e istruttori di creare corsi per i propri studenti e fornisce istruzione a distanza e altri programmi di apprendimento online più accessibili. Moodle offre una dashboard semplice, intuitiva e personalizzata che aiuta gli utenti ad accedere ai corsi attuali, passati o futuri e a rivedere il lavoro in sospeso. È progettato per insegnanti ed educatori che mirano a fornire un'istruzione tecnologicamente avanzata.

Questo tutorial ti mostrerà come installare Moodle con Nginx e Lets Encrypt SSL su Ubuntu 22.04.

Prerequisiti

  • Un server che esegue Ubuntu 22.04.
  • Un nome di dominio valido indicato con l'IP del tuo server.
  • Sul server è configurata una password di root.

Iniziare

Innanzitutto, devi aggiornare i tuoi pacchetti di sistema all'ultima versione. Puoi aggiornarli tutti eseguendo il seguente comando:

apt-get update -y

Una volta aggiornato il server, puoi procedere al passaggio successivo.

Installa Nginx, MariaDB e PHP

Prima di iniziare, dovrai installare Apache, MariaDB, PHP e altre librerie PHP sul tuo sistema. Innanzitutto, installa il server Apache e MariaDB utilizzando il seguente comando:

apt-get install nginx mariadb-server -y

Per impostazione predefinita, Ubuntu 22.04 viene fornito con la versione PHP 8.1 e Moodle non supporta questa versione PHP. Quindi dovrai installare PHP 7.4 sul tuo server.

Innanzitutto, installa tutte le dipendenze richieste utilizzando il seguente comando:

apt install software-properties-common ca-certificates lsb-release apt-transport-https -y

Successivamente, aggiungi il repository PHP al tuo server con il seguente comando:

add-apt-repository ppa:ondrej/php

Successivamente, aggiorna il repository utilizzando il seguente comando:

apt update

Una volta aggiornato il repository, installa PHP con le altre estensioni richieste utilizzando il seguente comando:

apt install 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-soap php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip unzip git curl -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:

memory_limit = 256M
max_input_vars = 6000

cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = UTC

Salva e chiudi il file, quindi riavvia il servizio PHP-FPM per applicare le modifiche:

systemctl restart php7.4-fpm

Una volta terminato, puoi procedere al passaggio successivo.

Crea un database per Moodle

Moodle utilizza MySQL o MariaDB come database back-end, quindi dovrai creare un database e un utente per Moodle.

Innanzitutto, connettiti alla shell MySQL con il seguente comando:

mysql

Una volta effettuato l'accesso, creare un database e un utente con il seguente comando:

CREATE DATABASE moodledb;
CREATE USER 'moodle'@'localhost' IDENTIFIED BY 'password';

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

GRANT ALL ON moodledb.* TO 'moodle'@'localhost' WITH GRANT OPTION;

Successivamente, scarica i privilegi ed esci da MySQL con il seguente comando:

FLUSH PRIVILEGES;
EXIT;

Successivamente, modifica il file di configurazione predefinito di MariaDB e definisci innodb_file_format:

nano /etc/mysql/mariadb.conf.d/50-server.cnf

Aggiungi le seguenti righe all'interno della sezione [mysqld]:

[mysqld]
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix = ON

Salva il file, quindi riavvia il servizio MariaDB per applicare le modifiche:

systemctl restart mariadb

Installa Moodle su Ubuntu 22.04

Innanzitutto, cambia la directory nella directory principale di Apache e scarica l'ultima versione di Moodle con il seguente comando:

cd /var/www/html
git clone -b MOODLE_400_STABLE git://git.moodle.org/moodle.git moodle

Quindi, imposta l'autorizzazione e la proprietà appropriate per Moodle:

mkdir -p /var/www/html/moodledata
chown -R www-data:www-data /var/www/html/moodle
chmod -R 755 /var/www/html/*
chown www-data:www-data /var/www/html/moodledata

Una volta terminato, puoi procedere al passaggio successivo.

Configura Nginx per Moodle

Successivamente, dovrai creare un file di configurazione dell'host virtuale Nginx per ospitare Moodle:

nano /etc/nginx/conf.d/moodle.conf

Aggiungi le seguenti righe:

server {
    listen 80;
    root /var/www/html/moodle;
    index  index.php index.html index.htm;
    server_name  moodle.example.com;

    client_max_body_size 100M;
    autoindex off;
    location / {
        try_files $uri $uri/ =404;
    }

    location /dataroot/ {
      internal;
      alias /var/www/html/moodledata/;
    }

    location ~ [^/].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;
    }
}

Salva e chiudi il file, quindi verifica Nginx per eventuali errori di sintassi con il seguente comando:

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

Infine, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Puoi anche controllare lo stato del servizio Nginx usando il seguente comando:

systemctl status nginx

Dovresti vedere il seguente output:

? 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) since Mon 2022-07-18 07:08:50 UTC; 26s ago
       Docs: man:nginx(8)
    Process: 51379 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 51382 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 51383 (nginx)
      Tasks: 3 (limit: 4579)
     Memory: 3.6M
        CPU: 64ms
     CGroup: /system.slice/nginx.service
             ??51383 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??51384 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??51385 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jul 18 07:08:50 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 18 07:08:50 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.

A questo punto, Nginx è configurato per ospitare Moodle. Ora puoi procedere al passaggio successivo.

Accedi all'interfaccia web di Moodle

Ora apri il tuo browser web e accedi all'interfaccia web di Moodle utilizzando l'URL http://moodle.example.com. Dovresti vedere la pagina di installazione di Moodle:

Seleziona la lingua e fai clic su Avanti. Dovresti vedere la seguente pagina:

Fornisci il tuo indirizzo web Moodle, il percorso della directory, il percorso della directory dei dati e fai clic su Avanti. Dovresti vedere la seguente pagina:

Selezionare il tipo di driver del database e fare clic su Avanti. Dovresti vedere la seguente pagina:

Fornire l'host del database, il nome del database, il nome utente, la password e fare clic su Avanti. Dovresti vedere la seguente pagina:

Fare clic su Continua per confermare tutte le condizioni. Dovresti vedere la seguente pagina:

Assicurati che tutte le estensioni PHP richieste siano installate, quindi fai clic su Continua. Dovresti vedere la seguente pagina:

Fare clic su Continua. Dovresti vedere la seguente pagina:

Fornisci il nome utente, la password, l'e-mail, il paese, il fuso orario dell'amministratore e fai clic su Aggiorna profilo. Dovresti vedere la seguente pagina:

Fornisci le impostazioni della prima pagina e fai clic sul pulsante Salva modifiche per salvare le modifiche.

Proteggi Moodle con Lets Encrypt SSL

Successivamente, dovrai installare lo strumento Certbot per scaricare Lets Encrypt SSL e configurare Nginx per utilizzare questo SSL.

Innanzitutto, installa Certbot con il seguente comando:

apt-get install python3-certbot-nginx -y

Una volta installato, esegui il seguente comando per scaricare tutto SSL e configurare Nginx per usarlo:

certbot --nginx -d moodle.example.com

Ti verrà chiesto di fornire un indirizzo email valido e di accettare i termini di 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): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 moodle.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/moodle.conf

Successivamente, scegli se reindirizzare o meno il traffico HTTP su HTTPS come mostrato di seguito:

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 continuare. Dovresti vedere il seguente output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/moodle.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://moodle.example.com

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/moodle.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/moodle.example.com/privkey.pem
   Your cert will expire on 2022-10-19. 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"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

È ora possibile accedere al sito Web di Moodle utilizzando l'URL http://moodle.example.com

Conclusione

Congratulazioni! hai installato correttamente Moodle con Nginx e Lets Encrypt SSL su Ubuntu 22.04. Ora puoi esplorare le funzionalità di Moodle e creare facilmente il tuo sistema di gestione dell'apprendimento online. Non esitate a chiedermi se avete domande