Matomo auf Debian installieren (mit https/ssl, php7.3, nginx, mariadb)

Matomo (ehemals Piwik) ist eine Opensource Software ähnlich Google Analytics mit der es möglich ist zahlreiche Kennzahlen über Webseitenbesucher und deren Nutzungsverhalten einzusehen. Dabei bietet Matomo inzwischen besonders durch die Erweiterbarkeit durch Plugins teilweise mehr Funktionen als Google Analytics.

Im folgendem Artikel beschreibe ich wie Matomo auf einem Debian Server eingerichtet wird. Dabei gehe ich von einem frisch aufgesetztem Server aus.

PHP 7.3

Die Entwickler von matomo empfehlen PHP7 zu verwenden da dies deutlich performanter läuft als PHP5. Ich gehe noch einen Schritt weiter und installiere PHP 7.3 da das die aktuellste Version ist und deutlich länger Support bekommt als PHP 7.0. oder PHP 7.2

Da PHP 7.3 nicht in den normalen Debian Repos verfügbar ist, installieren wir es wie folgt:

sudo apt-get install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt-get update
sudo apt-get install php7.3-fpm php7.3-curl php7.3-gd php7.3-cli php7.3-mysql php-xml php7.3-mbstring

TLS (SSL) Zertifikat für HTTPS

Die Verbindung zum Webserver per https zu verschlüsseln ist nicht optional. Matomo überträgt personebzeogne Daten und Nutzungsverhalten dessen Schutz wir als Betreiber sehr ernst nehmen müssen. Damit wir dem nachkommen und wir keine Probleme mit dem Datenschutz oder dem DSGVO bekommen, fordern wir ein kostenloses Lets Encrypt Zertifikat an:

sudo apt-get install certbot
certbot certonly -d example.com

Bitte ersetze „example.com“ durch deine Domain. Wenn Certbot fragt, wähle erstmal Antwort „2“.

NGINX

Installation

nginx ist einer der performantesten Webserver, weswegen ich seit Jahren keinen anderen Webserver mehr nutze. Die Installation geht einfach von der Hand:

sudo apt-get install nginx

Konfiguration

Um nginx zu konfigurieren, müssen wir folgende Datei bearbeiten: /etc/nginx/sites-enabled/default:

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}

# Default server configuration
#
server {
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

root /var/www/html;

index index.php index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ ^/(index|matomo|piwik|js/index).php {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}

## needed for HeatmapSessionRecording plugin
location = /plugins/HeatmapSessionRecording/configs.php {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_PROXY „“;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; #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;
}

}

MariaDB

Installation

sudo apt-get install mysql-server

Konfiguration

Wir benötigen für Matomo einen eigenen Mysql Benutzer und Datenbank. Diese legen wir an in dem wir in die MySQL Konsole wechseln:

mysql

CREATE DATABASE matomo;

CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'EIN-SICHERES-PASSWORT';

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON matomo.* TO 'matomo'@'localhost';

Damit ist auch die Einrichtung der MySQL Datenbank abgeschlossen.

Matomo

Zuerst laden wir uns die Datein auf den Server. Dazu wechsle ich in ein temporäres Verzeichnis

cd /tmp

wget https://builds.matomo.org/piwik.zip

unzip piwik.zip

mv piwik/* /var/www/html/

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

Nun können wir die Installation von Matomo über den Webbrowser starten dazu geben wir einfach die Domain in die Adresszeile ein.

3 Kommentare

Schreibe einen Kommentar zu Matthias Antworten abbrechen

E-Mail Adresse wird nicht veröffentlicht.


*