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 e può essere utilizzato per tenere traccia di indicatori chiave di prestazione come visite, download, tassi di conversione all'obiettivo, 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 Let's Encrypt SSL.
Prerequisiti
- Un server che esegue Ubuntu 20.04.
- Un nome di dominio valido puntato all'IP del tuo server.
- Una password di root è configurata sul server.
Per 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 comando seguente:
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 funziona 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 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 l'accesso, 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';
Quindi, svuota 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 Matomo
Innanzitutto, scarica l'ultima versione di Matomo nella directory principale 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, decomprimi il file scaricato con il seguente comando:
unzip matomo.zip
Quindi, cambia la proprietà del matomo in www-data:
chown -R www-data:www-data /var/www/html/matomo
Una volta terminato, 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/
Quindi, 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 Let's Encrypt SSL
È sempre una buona idea proteggere il tuo sito Web con Let's Encrypt SSL. Innanzitutto, installa il client Certbot Let's Encrypt nel tuo server con il seguente comando:
apt-get install python3-certbot-nginx -y
Una volta installato, proteggi il tuo sito web con Let's 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 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 matomo.linuxbuz.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/matomo.conf
Quindi, 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 Let's 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:
Fai clic su AVANTI pulsante. Dovresti vedere la schermata di controllo dei prerequisiti Matomo:
Fai clic su AVANTI pulsante. Dovresti vedere la schermata di configurazione del database di matomo:
Fornisci i dettagli del tuo database e fai clic su AVANTI pulsante. Dovresti vedere la seguente schermata:
Fai clic su AVANTI pulsante. Dovresti vedere la schermata di configurazione dell'utente amministratore:
Fornisci il tuo nome utente amministratore, password, e-mail e fai clic su AVANTI pulsante. Dovresti vedere la schermata di configurazione del sito web:
Fornisci i dettagli del tuo sito web e fai clic su AVANTI pulsante. Dovresti vedere la seguente schermata:
Fai clic su AVANTI pulsante. Una volta completata l'installazione, dovresti visualizzare 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 su ACCEDI pulsante. Dovresti vedere la dashboard Matomo nella schermata seguente:
Conclusione
Congratulazioni! hai installato e configurato correttamente l'analisi Matomo con Nginx e Let's Encrypt su Ubuntu 20.04. Ora puoi integrare il tuo sito Web con Matomo e iniziare a monitorare il tuo sito Web. Sentiti libero di chiedermi se hai domande.