Matomo Web Analytics installeren op Ubuntu 20.04
Matomo vroeger bekend als Piwik is een gratis en open-source web analytics toepassing die je helpt online bezoekers op je website te volgen. Het is een alternatief voor Google Analytics software dat je volledige controle geeft over je eigen website analytics en gegevens zonder oplossingen van derden te gebruiken. Het is ontworpen voor kleine en middelgrote bedrijven en kan gebruikt worden om Key Performance Indicators bij te houden, zoals bezoeken, downloads, omzettingspercentages voor doelen, trefwoorden, en nog veel meer.
In deze zelfstudie laten we je zien hoe je de Matomo web analytics software installeert op Ubuntu 20.04 met Nginx en Let’s Encrypt SSL.
Vereisten
- Een server met Ubuntu 20.04.
- Een geldige domeinnaam gericht met je server IP.
- Een root wachtwoord is op de server geconfigureerd.
Aan de slag
Eerst is het aan te raden je systeempakketten bij te werken met de nieuwste versie. Je kunt ze bijwerken door het volgende commando uit te voeren:
apt-get update -y
Als alle pakketten bijgewerkt zijn, installeer je andere vereiste afhankelijkheden door het volgende commando uit te voeren:
apt-get install curl wget vim git unzip socat gnupg2 -y
Nadat je alle vereiste pakketten geïnstalleerd hebt, kun je verder gaan met de volgende stap.
Installeer de LEMP server
Matomo draait op een webserver, geschreven in PHP en gebruikt MySQL voor de database. Dus moet de LEMP stack op je server geïnstalleerd zijn. Je kunt het installeren met het volgende commando:
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
Als de LEMP stack geïnstalleerd is, kun je verder gaan met de volgende stap.
Maak een Matomo database
Matomo heeft een database nodig om de analytics gegevens in op te slaan. Je zult dus een database en gebruiker voor Matomo moeten aanmaken.
Log eerst in op MariaDB met het volgende commando:
mysql
Na het inloggen maak je een database en gebruiker voor Matomo met het volgende commando:
MariaDB [(none)]> CREATE DATABASE matomodb;
MariaDB [(none)]> GRANT ALL ON matomodb.* TO 'matomo' IDENTIFIED BY 'password';
Spoel vervolgens de privileges en verlaat de MariaDB met het volgende commando:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Als je database gemaakt is, kun je verder gaan met de volgende stap.
Download Matomo
Download eerst de nieuwste versie van Matomo naar de Nginx web root directory van zijn officiële website met het volgende commando:
cd /var/www/html/
wget https://builds.matomo.org/matomo.zip
Eenmaal gedownload pak je het gedownloade bestand uit met het volgende commando:
unzip matomo.zip
Verander vervolgens het eigendom van de matomo in www-data:
chown -R www-data:www-data /var/www/html/matomo
Als je klaar bent kun je verder gaan met de volgende stap.
Configureer Nginx voor Matomo
Vervolgens moet je een nieuw Nginx virtual host configuratiebestand maken om Matomo te serveren.
nano /etc/nginx/sites-available/matomo.conf
Voeg de volgende regels toe:
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; } }
Sla het bestand op en sluit het af, activeer dan de virtuele host met het volgende commando:
ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled/
Controleer vervolgens de Nginx op eventuele configuratiefouten met het volgende commando:
nginx -t
Je zou de volgende uitvoer moeten zien:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Herstart tenslotte de Nginx dienst om de veranderingen toe te passen:
systemctl restart nginx
Op dit punt is Nginx geconfigureerd om Matomo te serveren. Je kunt nu verder gaan met de volgende stap.
Beveilig Matomo met Let’s Encrypt SSL
Het is altijd een goed idee om je website te beveiligen met Let’s Encrypt SSL. Installeer eerst de Certbot Let’s Encrypt client op je server met het volgende commando:
apt-get install python3-certbot-nginx -y
Eenmaal geïnstalleerd, beveilig je je website met Let’s Encrypt SSL door het volgende commando uit te voeren:
certbot --nginx -d matomo.linuxbuz.com
Je wordt gevraagd een geldig e-mail adres 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 matomo.linuxbuz.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/matomo.conf
Kies vervolgens of je HTTP verkeer al dan niet wilt omleiden naar HTTPS zoals hieronder:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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. Je zou de volgende output moeten zien:
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.
Nu is je Matomo website beveiligd met Let’s Encrypt SSL.
Toegang tot Matomo Analytics
Open nu je web browser en typ de URL https://matomo.linuxbuz.com. Je wordt doorgestuurd naar het Matomo welkomstscherm:
Klik op de NEXT knop. Je zou nu het Matomo voorwaardes check scherm moeten zien:
Klik op de NEXT knop. Je zou het matomo database configuratie scherm moeten zien:
Geef je database gegevens op en klik op de NEXT knop. Je zou het volgende scherm moeten zien:
Klik op de NEXT knop. Je zou het admin user setup scherm moeten zien:
Geef je admin gebruikersnaam, wachtwoord, e-mail en klik op de NEXT knop. Je zou het website instellingenscherm moeten zien:
Geef je website gegevens op en klik op de NEXT knop. Je zou het volgende scherm moeten zien:
Klik op de NEXT knop. Als de installatie voltooid is, zou je het volgende scherm moeten zien:
Klik op de knop CONTINUE TO MATOMO. Je wordt doorgestuurd naar het Matomo login scherm:
Geef je admin gebruikersnaam en wachtwoord op en klik op de SIGN IN knop. Je zou het Matomo dashboard moeten zien in het volgende scherm:
Conclusie
Gefeliciteerd! Je hebt met succes Matomo analytics met Nginx en Let’s Encrypt geïnstalleerd en geconfigureerd op Ubuntu 20.04. Je kunt nu je website integreren met Matomo en beginnen met het volgen van je website. Stel me gerust als je vragen hebt.