Installation d’un serveur Matomo (anciennement Piwik) |
Version de l’OS | Debian 9 |
Version de Matomo | 3.7.0 |
Pré-requis | Un CMS opérationnel |
Article original Publié le : 20 janvier 2019
Mise a jour le : 26 janvier 2019 |
- Installation des paquets nécessaires
- Configuration de Mariadb
- Installation de Matomo
- Configuration du vhost
- Génération du certificat avec Certbot
- Lancement de Matomo
- Revue des fonctionnalités
- Quelques liens utiles
Ce tuto se base sur arobaseinformatique.
Comme a mon habitude, j’y remplacerais Apache par Nginx, j’y ajouterais l’https ainsi qu’un certificat Certbot. |
Matomo, anciennement Piwik jusqu’au début de 2018, est un logiciel libre et open source de mesure de statistiques web, successeur de PhpMyVisites et conçu pour être une alternative libre à Google Analytics |
-
Installation des paquets
Installation des paquets php nécessaires
1 |
$ apt install php7.0 php7.0-mysql php7.0-cli php7.0-xml php7.0-mbstring php7.0-curl php7.0-pdo php7.0-gd php7.0-fpm |
État du service
1 |
$ sudo systemctl status php7.0-fpm |
La socket se trouve dans
1 |
/var/run/php/php7.0-fpm.sock |
/!\ Penser a désactiver apache2 qui est installé en dépendance.
Installation de Mariadb-server et nginx
1 |
$ sudo yum install install nginx mariadb-server |
État des services
1 |
$ sudo systemctl status nginx |
1 |
$ sudo systemctl status mariadb |
-
Configuration de Mariadb
Sécuriser a minima Mariadb
1 |
$ sudo mysql_secure_installation |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Set root password? [Y/n] <strong>Y</strong> New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! Remove anonymous users? [Y/n] <strong>Y</strong> ... Success! Disallow root login remotely? [Y/n] <strong>Y</strong> ... Success! Remove test database and access to it? [Y/n] <strong>Y</strong> - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reload privilege tables now? [Y/n] <strong>Y</strong> ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! |
Puis créer la db, l’utilisateur/mdp et allouer les privilèges.
1 |
MariaDB [(none)]> CREATE DATABASE <strong>db_matomo</strong> CHARACTER SET utf8; |
1 |
MariaDB [(none)]> GRANT ALL PRIVILEGES ON <strong>db_matomo.*</strong> TO '<strong>user_matomo</strong>'@'localhost' IDENTIFIED BY '<strong>password_matomo</strong>'; |
1 |
MariaDB [(none)]> FLUSH PRIVILEGES; |
-
Installation de Matomo
Récupérer la source depuis le site officiel
1 |
$ wget https://builds.matomo.org/matomo-latest.zip |
Décompresser le contenu dans www
1 |
$ sudo unzip matomo-latest.zip -d /var/www |
Affiner les droits utilisateur et groupe
1 |
$ sudo chown -R www-data:www-data /var/www/matomo |
Corriger les permissions sur les répertoires
1 |
$ sudo find /var/www/matomo -type d -exec chmod 755 {} \; |
Également les permissions sur les fichiers
1 |
$ sudo find /var/www/matomo -type f -exec chmod 644 {} \; |
-
Configuration du vhost
Supprimer le vhost par défaut et son lien
1 |
$ sudo rm /etc/nginx/sites-available/default |
1 |
$ sudo unlink /etc/nginx/sites-enabled/default |
Création du vhost Matomo
1 |
$ sudo vim /etc/nginx/sites-available/matomo.conf |
1 |
$ sudo ln -s /etc/nginx/sites-available/matomo.conf /etc/nginx/sites-enabled/matomo.conf |
Contenu du vhost, a adapter en fonction de la version php-fm installé.
/!\ Les certificats lets’encrypt sont commentés. Une fois générés, ils seront automatiquement rajoutés au vhost par Certbot, vérifier le chemin.
Création du vhost Matomo
/!\ MAJ du vhost sur https://it.izero.fr/web-mes-virtualhosts-sur-nginx
1 |
$ sudo vim /etc/nginx/sites-available/matomo.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
server { listen [::]:80; # remove this if you don't want Matomo to be reachable from IPv6 listen 80; server_name <strong>matomo.domaine.local</strong>; location / { # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response. return 301 https://$host$request_uri; } } server { listen [::]:443 ssl http2; # remove this if you don't want Matomo to be reachable from IPv6 listen 443 ssl http2; server_name <strong>matomo.domaine.local</strong>; # list all domains Matomo should be reachable from access_log /var/log/nginx/matomo.access.log; error_log /var/log/nginx/matomo.error.log; ## uncomment if you want to enable HSTS with 6 months cache ## ATTENTION: Be sure you know the implications of this change (you won't be able to disable HTTPS anymore) #add_header Strict-Transport-Security max-age=15768000; ## replace with your SSL certificate <span style="color: #ff0000;">#</span>ssl_certificate <strong>/etc/letsencrypt/live/matomo.domaine.local/fullchain.pem;</strong> <span style="color: #ff0000;">#</span>ssl_certificate_key <strong>/etc/letsencrypt/matomo.domaine.local/privkey.pem;</strong> include ssl.conf; # if you want to support older browsers, please read through this file add_header Referrer-Policy origin; # make sure outgoing links don't show the URL to the Matomo instance root /var/www/matomo/; # replace with path to your matomo instance index index.php; ## only allow accessing the following php files location ~ ^/(index|matomo|piwik|js/index).php { include snippets/fastcgi-php.conf; # if your Nginx setup doesn't come with a default fastcgi-php config replace this with the one from this repository fastcgi_param HTTP_PROXY ""; # prohibit httpoxy: https://httpoxy.org/ fastcgi_pass unix:<strong>/var/run/php/php7.0-fpm.sock</strong>; #replace with the path to your PHP socket file #fastcgi_pass 127.0.0.1:9000; # uncomment if you are using PHP via TCP sockets } ## needed for HeatmapSessionRecording plugin location = /plugins/HeatmapSessionRecording/configs.php { include snippets/fastcgi-php.conf; fastcgi_param HTTP_PROXY ""; fastcgi_pass unix:<strong>/var/run/php/php7.0-fpm.sock</strong>; #replace with the path to your PHP socket file #fastcgi_pass 127.0.0.1:9000; # uncomment if you are using PHP via TCP sockets } ## deny access to all other .php files location ~* ^.+\.php$ { deny all; return 403; } ## serve all other files normally location / { try_files $uri $uri/ =404; } ## disable all access to the following directories location ~ /(config|tmp|core|lang) { deny all; return 403; # replace with 404 to not show these directories exist } location ~ /\.ht { 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; ## Cache images,CSS,JS and webfonts for an hour ## Increasing the duration may improve the load-time, but may cause old files to show after an Matomo upgrade expires 1h; add_header Pragma public; add_header Cache-Control "public"; } location ~ /(libs|vendor|plugins|misc/user) { deny all; return 403; } ## properly display textfiles in root directory location ~/(.*\.md|LEGALNOTICE|LICENSE) { default_type text/plain; } } # vim: filetype=nginx |
Créer également le fichier “ssl.conf” a la racine de Nginx
1 |
$ sudo vim /etc/nginx/ssl.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
## ## Modern profile created with the Mozilla SSL Configuration Generator ## Oldest compatible clients: Firefox 27, Chrome 30, IE 11 on Windows 7, Edge, Opera 17, Safari 9, Android 5.0, and Java 8 ## If you need to support older clients, create your own config here ## https://mozilla.github.io/server-side-tls/ssl-config-generator/ ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; # modern configuration. tweak to your needs. ssl_protocols TLSv1.2; ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256'; ssl_prefer_server_ciphers on; # OCSP Stapling --- # fetch OCSP records from URL in ssl_certificate and cache them ssl_stapling on; ssl_stapling_verify on; # vim: filetype=nginx |
Tester et recharger la conf
1 |
$ sudo nginx -t |
1 |
$ systemctl reload nginx |
/!\ Si il y a plusieurs vhost sur la machine, il y a probablement plusieurs conf ssl et donc succeptible d’avoir l’erreur suivante au test
Cela provient de la directive ci dessous qui est en conflit
remplacer par
Puis relancer le nginx -t |
-
Generation du certificat avec Certbot
Dans les grandes lignes voici un récap, sinon suivre la doc ci-dessous.
1 |
$ sudo certbot-auto |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Which names would you like to activate HTTPS for? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: monsite.domaine.local 2: <strong>matomo.domaine.local </strong><span style="color: #ff0000;">#<--Sélectionner le domaine</span> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): <strong>2</strong> Obtaining a new certificate Performing the following challenges: http-01 challenge for matomo.domaine.local Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/matomo.conf 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. <strong>2: Redirect</strong> - 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): <strong>2 </strong><span style="color: #ff0000;">#<-- mode Redirect</span> Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/matomo.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://matomo.domaine.local You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=matomo.domaine.local - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/matomo.domaine.local/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/matomo.domaine.local/privkey.pem Your cert will expire on 2019-04-19. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - 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 |
Doc disponible d’installation et de génération de certificat ci dessous
https://it.izero.fr/certificat-installation-de-cerbot/
Normalement Certbot reload le service Nginx a l’issue pour la prise en compte du certificat.
-
Lancement de Matomo
Depuis le navigateur, se connecter a l’url de matomo et procéder a son installation
Vérifier le pré-requis, corriger a besoin.
Configurer les infos pour la db
Validation des infos
Créer le compte admin pour l’administration de Matomo
Configurer le 1er site web a analyser et le fuseau horaire
Il y a un code JavaScript a placer dans le header du site.
Pour WordPress c’est dans le footer.php du thème
Enfin valider la fin de l’installation, par defaut il active l’anonymisation a minima.
-
Revue des fonctionnalités
Page de connexion
Petit tour rapide des onglets dans l’administration
Personnel -> Paramètres = 2 paramètres a vérifier, le jeton d’API et l’exclusion de sa propre adresse ip des stats
Personnel -> Rapports e-mail = Pour créer et planifier des rapports de stats, assez complet dans les requettes
Système -> Paramètres généraux = Parametrage d’archivage, du serveur mail, des variables Nginx …
Système -> Utilisateurs = Pour creer d’autres utilisateurs avec des droits limité ou admin
Système -> Plugins = Pas mal de plugins pré-installés, il est possible d’installer d’autres plugins depuis le store
Système -> Géolocalisation = Pour confer le fournisseur de location (voir Diagnostic -> Vérification du système)
Système -> Messagerie Mobile = Pour des rapport sms, pas trop d’interet
Vie privée -> Anonymiser les données = Tout plein d’option pour l’anonymisation
Vie privée -> Désinscription des utilisateurs = Differente option contre le tracking, par defaut activé la prise en charge de ne pas suivre.
Vie privée -> Demande de permission = Un code de consentement en Javascript pour le rgpd
Vie privée -> Vue d’ensemble RGPD = Le règlement général sur la protection des données (RPGD)
Vie privée -> Outils RGPD = Des outils pour le rgpd
Site Web -> Gérer = Permet de gérer les options du site a analyser
Site Web -> Paramètres = Cet onglet est global a tous les sites web a analyser.
Site Web -> Code de Suivi = On retrouve les différentes options de suivi comme le code JavaScript a insérer dans le header.
Site Web -> Objectifs = Pour avoir un suivi particulier sur une page, un fichier télécharge, un événement ..
Plate-forme -> Marché = Le store de matomo
Plate-forme -> Widgets = Des widgets pour la page d’accueil
Plate-forme -> API = Les APIs
Diagnostic -> Vérification du système = Un audit rapide sur l’etat du systeme
Pour la correction de ces 2 problèmes ci dessus
Pour la connexion SSL forcé, éditer le fichier config.ini.php
1 |
$ sudo vim /var/www/matomo/config/config.ini.php |
Ajouter force_ssl = 1 dans l’onglet Général
—
Pour la géolocalisation, aller dans Systemes / Géolocalisation
Suivez les instructions, récupérer la source et déplacer le fichier dans le répertoire misc de motomo
1 |
$ wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz && tar xvf GeoLite2-City.tar.gz && rm GeoLite2-City.tar.gz |
1 |
$ sudo mv /GeoLite2-City_20190115/GeoLite2-City.mmdb /var/www/matomo/misc/ && rm City_20190115 -rf |
Puis rafraîchir la page Système / Géolocalisation
Diagnostic -> Variable personnalisées = Pas trop regardé son intérêt
Diagnostic -> Fichier de configuration = Toute la conf du site que l’on retrouve dans config.ini.php
Diagnostic -> Détection du périphérique = Un navigateur est égale a un périphérique
Reste 2 Onglets, le tableau de bord et la valeur des sites web
Le tableau de board fraichement installé, d’ici 24h commencera a apparaitre des graphs.
La monétisation du site web, il faudra attendre 24h pour avoir les premiers chiffres en fonctions de l’affluence.
-
Quelques liens utiles
Source
http://arobaseinformatique.eklablog.com/installer-matomo-sur-debian-stretch-a135767160
https://github.com/matomo-org/matomo-nginx
https://github.com/certbot/certbot/issues/921#issuecomment-297863708
je vois que l’interface de matomo depuis mon tuto…
Je vois dans ton tuto que tu as crée un certificat cerbot pour ton matomo.domaine.local
Je pensais que cerbot n’était réservé qu’aux noms domaines valides et ne fonctionnait pas avec les noms de domaine .local
Hello,
Oui pour la doc, j’ai volontairement mis domaine.local pour ne pas afficher les informations du site en question.
Mais effectivement Certbot ne fonctionne qu’avec des domaines valides.
Très bon tuto !!
Pour Nginx, tu utilises un générateur de configuration ?
cdt
Merci pour la base !
Pour la conf Nginx, j’ai usé de facilité pour matomo en utilisant le repo git matomo-nginx.
Celui ci manque d’ailleurs de quelques directives car avec securityheaders.com je reçois un D.
Je vais corriger et compléter la doc rapidement