Ricerca nel sito web

Come installare MediaWiki con Nginx e crittografare SSL su Ubuntu 20.04


Questo tutorial esiste per queste versioni del sistema operativo

  • Ubuntu 20.04 (Focal Fossa)
  • Ubuntu 16.04 (Xenial Xerus)

Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa Nginx, MariaDB e PHP
  4. Crea un database MariaDB
  5. Scarica MediaWiki
  6. Configura Nginx per MediaWiki
  7. Accedi all'interfaccia utente Web di MediaWiki
  8. Proteggi MediaWiki con Lets Encrypt SSL
  9. Conclusione

MediaWiki è un software wiki open source scritto in PHP. Ti consente di creare il tuo sito Web wiki self-hosted sul server. È una delle piattaforme wiki più popolari grazie alla sua semplicità e personalizzazione. Attualmente è utilizzato da molte aziende per gestire le proprie pagine wiki. Fornisce uno strumento versatile e gratuito per la pubblicazione di contenuti su Internet.

In questo tutorial, ti mostreremo come installare MediaWiki con il server web Nginx e Lets Encrypt SSL su Ubuntu 20.04.

Prerequisiti

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

Iniziare

Innanzitutto, aggiorna i pacchetti di sistema alla versione aggiornata eseguendo il seguente comando:

apt-get update -y

Una volta aggiornati tutti i pacchetti, puoi procedere al passaggio successivo.

Installa Nginx, MariaDB e PHP

MediaWiki richiede il server web Nginx, il server database MariaDB, PHP e altre estensioni. Puoi installarli tutti con il seguente comando:

apt-get install nginx mariadb-server php php-fpm php-mbstring php-xml php-json php-mysql php-curl php-intl php-gd php-mbstring texlive imagemagick unzip -y

Una volta installati tutti i pacchetti, installa Composer con il seguente comando:

apt-get install composer -y

Successivamente, modifica il file php.ini e modifica le impostazioni predefinite:

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

Modifica le seguenti righe:

memory_limit = 512M
post_max_size =32M
upload_max_filesize = 32M
date.timezone = Asia/Kolkata

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

systemctl restart php7.4-fpm

Una volta terminato, puoi procedere al passaggio successivo.

Crea un database MariaDB

MediaWiki utilizza MariaDB come backend del database, quindi dovrai creare un database e un utente per MediaWiki.

Innanzitutto, connettiti a MariaDB con il seguente comando:

mysql

Una volta connesso, crea un database e un utente con il seguente comando:

MariaDB [(none)]> CREATE DATABASE mediadb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mediadb.* TO 'mediauser'@'localhost' IDENTIFIED BY 'password';

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

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

Una volta terminato, puoi procedere al passaggio successivo.

Scarica MediaWiki

Primo. vai al sito web di MediaWiki e scegli l'ultima versione di MediaWiki. Quindi, esegui il seguente comando per scaricarlo sul tuo server:

wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.zip

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

unzip mediawiki-1.35.2.zip

Successivamente, sposta la directory estratta nella directory root web di Nginx con il seguente comando:

mv mediawiki-1.35.2 /var/www/html/mediawiki

Quindi, cambia la directory in MediaWiki e installa tutte le dipendenze PHP con il seguente comando:

cd /var/www/html/mediawiki
composer install --no-dev

Una volta installate tutte le dipendenze, imposta i permessi e la proprietà appropriati con il seguente comando:

chown -R www-data:www-data /var/www/html/mediawiki
chmod -R 755 /var/www/html/mediawiki

Una volta terminato, puoi procedere al passaggio successivo.

Configura Nginx per MediaWiki

Successivamente, dovrai creare un file di configurazione dell'host virtuale Nginx per MediaWiki. Puoi crearlo con il seguente comando:

nano /etc/nginx/conf.d/wiki.conf

Aggiungi le seguenti righe:

server {
        listen 80;
        server_name wiki.example.com;

        root /var/www/html/mediawiki;
        index index.php;
   
        error_log /var/log/nginx/mediawiki.error;
        access_log /var/log/nginx/mediawiki.access;

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


        location ~ /\.ht {
          deny all;
         }

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

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

nginx -t

Dovresti vedere il seguente output:

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

Successivamente, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Puoi anche verificare lo stato di Nginx con 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 Wed 2021-06-02 05:06:48 UTC; 3s ago
       Docs: man:nginx(8)
    Process: 24594 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24605 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 24606 (nginx)
      Tasks: 2 (limit: 2353)
     Memory: 2.8M
     CGroup: /system.slice/nginx.service
             ??24606 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??24607 nginx: worker process

Jun 02 05:06:48 ubunt4 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 02 05:06:48 ubunt4 systemd[1]: Started A high performance web server and a reverse proxy server.

Accedi all'interfaccia utente Web di MediaWiki

Ora, apri il tuo browser web e digita l'URL http://wiki.example.com. Verrai reindirizzato alla seguente pagina:

Ora, fai clic sul pulsante Imposta il wiki. Dovresti vedere la seguente pagina:

Qui, scegli la tua lingua wiki e fai clic sul pulsante Continua. Dovresti vedere la seguente pagina:

Ora, fai clic sul pulsante Continua. Dovresti vedere la seguente pagina:

Ora, fornisci i dettagli del tuo database e fai clic sul pulsante Continua. Dovresti vedere la seguente pagina:

Selezionare usa lo stesso account utilizzato per l'installazione e fare clic sul pulsante Continua. Dovresti vedere la seguente pagina:

Ora, fornisci il nome, il nome utente e la password del tuo sito wiki. Quindi, fai clic sul pulsante Continua. Dovresti vedere la seguente pagina:

Fare clic sul pulsante Continua per avviare l'installazione. Dovresti vedere la seguente pagina:

Fare clic sul pulsante Continua. Una volta terminata l'installazione, dovresti vedere la seguente pagina:

Ora, fai clic sul pulsante di download per scaricare il file LocalSettings.php sul tuo sistema. Quindi, copia questo file sul tuo server all'interno della directory principale di MediaWiki e imposta i permessi appropriati con il seguente comando:

chown www-data:www-data /var/www/html/mediawiki/LocalSettings.php

Quindi, torna al tuo browser web e fai clic su entra nel tuo wiki. Dovresti vedere la dashboard di MediaWiki nella pagina seguente:

Proteggi MediaWiki con Lets Encrypt SSL

Successivamente, dovrai installare il pacchetto client Certbot per installare la gestione di Lets Encrypt SSL.

Innanzitutto, installa Certbot con il seguente comando:

apt-get install python3-certbot-nginx -y

Al termine dell'installazione, esegui il seguente comando per installare Lets Encrypt SSL sul tuo sito web:

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

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

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

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

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/wiki.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/wiki.example.com/privkey.pem
   Your cert will expire on 2021-12-30. 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 il tuo sito web è protetto con Lets Encrypt SSL. Puoi accedervi in modo sicuro utilizzando l'URL https://wiki.example.com.

Conclusione

Congratulazioni! hai installato con successo MediaWiki con Nginx e Lets Encrypt SSL su Ubuntu 20.04. Ora puoi facilmente ospitare il tuo sito wiki con MediaWiki.