Matomo im DDEV installieren

Matomo ist eine beliebte alternative zu Google Analytics. Möchte man eine Integration erst lokal testen und einrichten ist DDEV eine gute Wahl, da eine gänige Integration in TYPO3, WordPress, Drupal oder ähnliches gleich zusammen getestet und aufgesetzt werden kann.

Um einen neuen Service anzulegen legen wir erst mal eine neue Config Datei im .ddev Verzeichnis an: docker-compose.matomo.yaml

version: '3.6'

services:
  matomo:
    image: matomo:4-fpm-alpine
    container_name: ddev-${DDEV_SITENAME}-matomo
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: ${DDEV_APPROOT}
    restart: "always"
    links:
      - db
    environment:
      - MYSQL_USER=root
      - MYSQL_PASSWORD=root
      - MYSQL_DATABASE=matomo
      - MATOMO_DATABASE_HOST=db
      - MATOMO_DATABASE_ADAPTER=myslqi
      - MATOMO_DATABASE_TABLES_PREFIX=matomo_
      - MATOMO_DATABASE_USERNAME=root
      - MATOMO_DATABASE_PASSWORD=root
      - MATOMO_DATABASE_DBNAME=matomo
    volumes:
      - type: bind
        source: ../matomo/
        target: /var/www/html
        consistency: cached

Damit wir Matomo auch über eine Url erreichen fügen wir noch eine nginx config in .ddev/nginx_full/matomo.conf an:

server {
    root /var/www/html/matomo;
    server_name matomo.ddev.site;

    listen 80;
    listen 443 ssl;

    ssl_certificate /etc/ssl/certs/master.crt;
    ssl_certificate_key /etc/ssl/certs/master.key;

	index index.php;

	add_header Referrer-Policy origin; # make sure outgoing links don't show the URL to the Matomo instance

    sendfile off;
    error_log /dev/stdout info;
    access_log /var/log/nginx/access.log;

	## only allow accessing the following php files
	location ~ ^/(index|matomo|piwik|js/index|plugins/HeatmapSessionRecording/configs).php {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass matomo:9000;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_intercept_errors off;
        # fastcgi_read_timeout should match max_execution_time in php.ini
        fastcgi_read_timeout 10m;
        fastcgi_param SERVER_NAME $host;
        fastcgi_param HTTPS $fcgi_https;
	}

	## deny access to all other .php files
	location ~* ^.+\.php$ {
		deny all;
		return 403;
	}

	## 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 ~ js/container_.*_preview\.js$ {
		expires off;
		add_header Cache-Control 'private, no-cache, no-store';
	}
	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;
	}
}

Damit ddev uns einen weiteren vHost anlegt fügen wir noch einen Eintrag in .ddev/config.yaml hinzu:

additional_hostnames: ["matomo"]

Abschließend solltet ihr noch ein "ddev restart" ausführen. Nun könnt ihr über https://matomo.ddev.site/ eure lokale Instanz initialisieren.

Kategorien

Devblog

Tags

Devtools TYPO3 Wordpress

Hat Dir der Artikel gefallen?