DEV Community

Cody Meadows
Cody Meadows

Posted on

Running Matomo & GlitchTip with Dokku

I've been meaning to set up analytics and error reporting for my sites for a while now, and finally got around to it today. I'd heard Dokku was a good way to deploy resources like this, and while it worked pretty well in the end, some of the examples for these apps were quite dated.

Thought I'd share my new instructions on these.

Matomo

https://github.com/rclement/dokku-matomo

  • I originally found this guide, but some of the instructions are dated and gave me trouble. Below should be a more accurate guide on running Matomo with the current version of Dokku.

Deploy your own instance of Matomo on Dokku.

This setup is makes use of the great ready-to-use matomo-docker image by crazy-max, which does all of the heavy-lifting to properly deploy Matomo without too much headache.

Requirements

App and database

First create a new Dokku app. We will call it matomo.

dokku apps:create matomo
Enter fullscreen mode Exit fullscreen mode

Next create the MariaDB database required by Matomo and link it to the app.

dokku mariadb:create mariadb-matomo
dokku mariadb:link mariadb-matomo matomo
Enter fullscreen mode Exit fullscreen mode

Configuration

Main configuration

dokku config:set --no-restart matomo TZ=America/Chicago
dokku config:set --no-restart matomo MEMORY_LIMIT=256M
dokku config:set --no-restart matomo UPLOAD_MAX_SIZE=16M
dokku config:set --no-restart matomo OPCACHE_MEM_SIZE=128
dokku config:set --no-restart matomo REAL_IP_FROM=0.0.0.0/32
dokku config:set --no-restart matomo REAL_IP_HEADER=X-Forwarded-For
dokku config:set --no-restart matomo LOG_LEVEL=WARN
Enter fullscreen mode Exit fullscreen mode

Persistent storage

You need to mount a volume on your host (the machine running Dokku) to persist all settings that you set in the Matomo interface.

mkdir /var/lib/dokku/data/storage/matomo
# UID:GUID are set to 101. These are the values the nginx image uses,
# that is used by crazymax/matomo
chown 101:101 /var/lib/dokku/data/storage/matomo
dokku storage:mount matomo /var/lib/dokku/data/storage/matomo:/data
Enter fullscreen mode Exit fullscreen mode

Domain setup

To get the routing working, we need to apply a few settings. First we set the domain.

dokku domains:add matomo matomo.example.com
Enter fullscreen mode Exit fullscreen mode

We also need to update the ports set by Dokku.

dokku ports:set matomo http:80:8000
dokku ports:remove matomo http:80:5000
Enter fullscreen mode Exit fullscreen mode

If Dokku proxy:report shows more than one port mapping, remove all port mappings except the added above.

Deploy app for the first time

Deploy Matomo from latest version of the docker image

dokku git:from-image matomo crazymax/matomo:latest
Enter fullscreen mode Exit fullscreen mode

Setup Let's Encrypt

Setup an SSL certificate via Let's Encrypt.

dokku letsencrypt:set matomo email user@domain.com
dokku letsencrypt:enable matomo
dokku letsencrypt:auto-renew matomo
Enter fullscreen mode Exit fullscreen mode

Grep MariaDB information for the setup

We will need to set up Matomo in the web interface and provide the database details. You should be able to access the page via https://matomo.example.com.

Run the command below to retrieve the DSN.

dokku mariadb:info mariadb-matomo
Enter fullscreen mode Exit fullscreen mode

An example DSN might look like this: mysql://mariadb:ffd4fc238ba8adb3@dokku-mariadb-mariadb-matomo:3306/mariadb_matomo. Copy and paste the details as follows:

Hostname: dokku-mariadb-mariadb-matomo
Username: mariadb
Password: ffd4fc238ba8adb3
Database Name: mariadb_matomo

After going through the setup, you should be able to use Matomo.

GlitchTip

I was originally planning to use Sentry, but they've really made it a pain to self-host. They pretty much require you to use docker compose, which Dokku doesn't appear to have solid support for. Or at least, documentation.

I would probably need a dedicated machine or proper Docker environment to run it alongside other applications such as Matomo.
So I looked for lighter weight error reporting applications and came across GlitchTip, which seems to fit the bill.

Didn't see any Dokku instructions for this one, but the following worked for me:

Install Dokku plugins

Go to your dokku server and install following plugins:

Install official postgresql plugin

sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
Enter fullscreen mode Exit fullscreen mode

Install official redis plugin

sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis
Enter fullscreen mode Exit fullscreen mode

Prepare dokku

Create dokku app

dokku apps:create glitchtip
Enter fullscreen mode Exit fullscreen mode

Create postgresql db and link it to the app

dokku postgres:create glitchtip
dokku postgres:link glitchtip glitchtip
Enter fullscreen mode Exit fullscreen mode

Create redis instance and link it to the app

dokku redis:create glitchtip
dokku redis:link glitchtip glitchtip
Enter fullscreen mode Exit fullscreen mode

Set required variables for GlitchTip

dokku config:set --no-restart glitchtip SECRET_KEY=$(echo `openssl rand -base64 64` | tr -d ' ')
dokku config:set --no-restart glitchtip GLITCHTIP_DOMAIN=https://glitchtip.example.com
dokku config:set --no-restart glitchtip GLITCHTIP_DOMAIN="smtp://email:password@smtp_url:port"
Enter fullscreen mode Exit fullscreen mode

Domain setup

dokku domains:add glitchtip glitchtip.example.com
Enter fullscreen mode Exit fullscreen mode

We also need to update the ports set by Dokku.

dokku ports:set glitchtip http:80:8080
dokku ports:remove glitchtip http:80:5000
Enter fullscreen mode Exit fullscreen mode

If Dokku proxy:report shows more than one port mapping, remove all port mappings except the added above.

Deploy

Deploy Matomo from their docker image

dokku git:from-image glitchtip glitchtip/glitchtip
Enter fullscreen mode Exit fullscreen mode

Setup Let's Encrypt

Setup an SSL certificate via Let's Encrypt.

dokku letsencrypt:set glitchtip email user@domain.com
dokku letsencrypt:enable glitchtip
dokku letsencrypt:auto-renew glitchtip
Enter fullscreen mode Exit fullscreen mode

You should then be able to access glitchtip.example.com and create the first user account.

Top comments (0)