Ricerca nel sito web

Come installare Matomo Web Analytics su Ubuntu 20.04


Questo tutorial esiste per queste versioni del sistema operativo

  • Ubuntu 18.04 (Castoro bionico)

Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa il server LEMP
  4. Crea database Matomo
  5. Scarica Matomo
  6. Configura Nginx per Matomo
  7. Proteggi Matomo con Lets Encrypt SSL
  8. Accedi a Matomo Analytics
  9. Conclusione

Matomo precedentemente noto come Piwik è un'applicazione di analisi web gratuita e open source che ti aiuta a tenere traccia dei visitatori online sul tuo sito web. È un'alternativa al software Google Analytics che ti offre il pieno controllo delle analisi e dei dati del tuo sito Web senza utilizzare soluzioni di terze parti. È progettato per le piccole e medie imprese che possono essere utilizzate per tenere traccia degli indicatori chiave di prestazione come visite, download, tassi di conversione degli obiettivi, parole chiave e molti altri.

In questo tutorial, ti mostreremo come installare il software di analisi web Matomo su Ubuntu 20.04 con Nginx e Lets Encrypt SSL.

Prerequisiti

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

Iniziare

Innanzitutto, si consiglia di aggiornare i pacchetti di sistema con l'ultima versione. Puoi aggiornarli eseguendo il seguente comando:

apt-get update -y

Una volta aggiornati tutti i pacchetti, installa le altre dipendenze richieste eseguendo il seguente comando:

apt-get install curl wget vim git unzip socat gnupg2 -y

Dopo aver installato tutti i pacchetti richiesti, puoi procedere al passaggio successivo.

Installa il server LEMP

Matomo gira su un server web, scritto in PHP e utilizza MySQL per il database. Quindi lo stack LEMP deve essere installato nel tuo server. Puoi installarlo con il seguente comando:

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

Una volta installato lo stack LEMP, puoi procedere al passaggio successivo.

Crea un database Matomo

Matomo richiede un database per archiviare i dati analitici. Quindi dovrai creare un database e un utente per Matomo.

Innanzitutto, accedi a MariaDB con il seguente comando:

mysql

Dopo il login, crea un database e un utente per Matomo con il seguente comando:

MariaDB [(none)]> CREATE DATABASE matomodb;
MariaDB [(none)]> GRANT ALL ON matomodb.* TO 'matomo' IDENTIFIED BY 'password';

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

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

Una volta creato il database, puoi procedere al passaggio successivo.

Scarica Matomó

Innanzitutto, scarica l'ultima versione di Matomo nella directory radice web di Nginx dal suo sito Web ufficiale con il seguente comando:

cd /var/www/html/
wget https://builds.matomo.org/matomo.zip

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

unzip matomo.zip

Successivamente, modifica la proprietà del matomo in www-data:

chown -R www-data:www-data /var/www/html/matomo

Al termine, puoi procedere al passaggio successivo.

Configura Nginx per Matomo

Successivamente, dovrai creare un nuovo file di configurazione dell'host virtuale Nginx per servire Matomo.

nano /etc/nginx/sites-available/matomo.conf

Aggiungi le seguenti righe:

server {

  listen 80;
  server_name matomo.linuxbuz.com;
  root /var/www/html/matomo/;
  index index.php;

  location ~ ^/(index|matomo|piwik|js/index).php {
    include snippets/fastcgi-php.conf;
    fastcgi_param HTTP_PROXY ""; 
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; 
  }
  
  location = /plugins/HeatmapSessionRecording/configs.php {
    include snippets/fastcgi-php.conf;
    fastcgi_param HTTP_PROXY "";
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  }

  location ~* ^.+\.php$ {
    deny all;
    return 403;
  }

  location / {
    try_files $uri $uri/ =404;
  }
  
  location ~ /(config|tmp|core|lang) {
    deny all;
    return 403;
  }

  location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2|json)$ {
    allow all;
  }

  location ~ /(libs|vendor|plugins|misc/user) {
    deny all;
    return 403;
  }

}

Salva e chiudi il file quindi attiva l'host virtuale con il seguente comando:

ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled/

Successivamente, controlla Nginx per eventuali errori di configurazione 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

Infine, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

A questo punto, Nginx è configurato per servire Matomo. Ora puoi procedere al passaggio successivo.

Proteggi Matomo con Lets Encrypt SSL

È sempre una buona idea proteggere il tuo sito web con Lets Encrypt SSL. Innanzitutto, installa il client Certbot Lets Encrypt nel tuo server con il seguente comando:

apt-get install python3-certbot-nginx -y

Una volta installato, proteggi il tuo sito web con Lets Encrypt SSL eseguendo il seguente comando:

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

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/matomo.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/matomo.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-10-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 Matomo è protetto con Lets Encrypt SSL.

Accedi a Matomo Analytics

Ora apri il tuo browser web e digita l'URL https://matomo.linuxbuz.com. Verrai reindirizzato alla schermata di benvenuto di Matomo:

Fare clic sul pulsante AVANTI. Dovresti vedere la schermata di controllo dei prerequisiti di Matomo:

Fare clic sul pulsante AVANTI. Dovresti vedere la schermata di configurazione del database matomo:

Fornisci i dettagli del tuo database e fai clic sul pulsante AVANTI. Dovresti vedere la seguente schermata:

Fare clic sul pulsante AVANTI. Dovresti vedere la schermata di configurazione dell'utente amministratore:

Fornisci il nome utente, la password, l'e-mail dell'amministratore e fai clic sul pulsante AVANTI. Dovresti vedere la schermata di configurazione del sito web:

Fornisci i dettagli del tuo sito web e fai clic sul pulsante AVANTI. Dovresti vedere la seguente schermata:

Fare clic sul pulsante AVANTI. Una volta completata l'installazione, dovresti vedere la seguente schermata:

Fare clic su CONTINUA A MATOMO. Verrai reindirizzato alla schermata di accesso di Matomo:

Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante ACCEDI. Dovresti vedere la dashboard di Matomo nella seguente schermata:

Conclusione

Congratulazioni! hai installato e configurato correttamente Matomo analytics con Nginx e Lets Encrypt su Ubuntu 20.04. Ora puoi integrare il tuo sito web con Matomo e iniziare a monitorare il tuo sito web. Non esitate a chiedermi se avete domande.