Hosting Plausible Analytics on Dokku (2024 Edition)

Plausible is an application that provides web analytics but actually respects your users privacy. Below are the instructions on how to install Plausible on Dokku.

This is a modified version of the work done by Bart Mathijssen which is the modified version of the work done by Kevin Langley Jr.

I made some modifications to the article, changed deployment to using dokku git:from-image instead of a custom Dockerfile and switched to pulling the Docker image from the GitHub Container Registry since images no longer seem to be published to Docker Hub.

Installation

First, you need to SSH into your Dokku Host and create the Plausible app:

dokku apps:create plausible

Next, you need to install the PostgreSQL and Clickhouse plugins, if they aren’t already installed.

dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku plugin:install https://github.com/dokku/dokku-clickhouse.git clickhouse

Create the instances of the PostgresSQL and Clickhouse databases.

dokku postgres:create plausible-db
dokku clickhouse:create plausible-events-db

Then link the databases to the application (ignore “App image (dokku/plausible:latest) not found” message in the next steps).

dokku config:set plausible CLICKHOUSE_DATABASE_SCHEME=http
dokku postgres:link plausible-db plausible
dokku clickhouse:link plausible-events-db plausible

Next, you’ll slightly adjust the URL that was provided from linking the Clickhouse database and change the name of the environment variable for it as well to match what is expected within the Plausible docker image.

dokku config:set plausible \
  CLICKHOUSE_DATABASE_URL=$(dokku config:get plausible CLICKHOUSE_URL)/plausible_events_db
dokku config:unset plausible CLICKHOUSE_URL

Then you need to generate a secrete key using openssl.

dokku config:set plausible SECRET_KEY_BASE=$(openssl rand -base64 64 | tr -d '\n')

And then, we’ll set the BASE_URL environment variable and set the domain for the application — make sure to use your domain here.

dokku config:set plausible BASE_URL=https://analytics.example.com
dokku domains:set plausible analytics.example.com

Set the required SMTP environment variables to set up transactional emails.

dokku config:set plausible MAILER_EMAIL=admin@example.com \
                           SMTP_HOST_ADDR=mail.example.com \
                           SMTP_HOST_PORT=465 \
                           SMTP_USER_NAME=admin@example.com \
                           SMTP_USER_PWD=password \
                           SMTP_HOST_SSL_ENABLED=true

If you happen to be using Fastmail for outgoing mail, set up a new SMTP-only app password in Settings / Privacy & Security / Connected apps & API tokens / Manage app passwords (access: SMTP).

Then configure Plausible with:

dokku config:set plausible MAILER_EMAIL=sender@yourdomain.com \
                           SMTP_HOST_ADDR=smtp.fastmail.com \
                           SMTP_HOST_PORT=587 \
                           SMTP_USER_NAME=username@yourdomain.com \
                           SMTP_USER_PWD=<the app password> \
                           SMTP_HOST_SSL_ENABLED=false

Deploy Plausible to Dokku directly from the official Docker image.

dokku git:from-image plausible ghcr.io/plausible/community-edition:v2

Override the default (wrong) port mapping:

dokku ports:add plausible http:80:8000
dokku ports:remove plausible http:8000:8000

Initialize the databases:

dokku run plausible /entrypoint.sh db createdb
dokku run plausible /entrypoint.sh db migrate

Finally, you can generate the Let’s Encrypt SSL certificates.

dokku letsencrypt:enable plausible

Now open https://analytics.example.com and set up the first account.

Once the first account is set up, only invited users can set up new accounts. Override this with the DISABLE_REGISTRATION environment variable.