Run Plausible on Dokku
Perquisites
What is Plausible?
Plausible is a lightweight and open-source website analytics tool. No cookies and fully compliant with GDPR, CCPA and PECR.
What is Dokku?
Dokku is the smallest PaaS implementation you've ever seen - Docker powered mini-Heroku.
Requirements
- A working Dokku host
- PostgreSQL plugin for Dokku
- Clickhouse plugin for Dokku
- Letsencrypt plugin for SSL (optionnal)
Setup
Note: We are going to use the domain plausible.example.com
for demonstration purposes. Make sure to
replace it with your own domain name.
App and plugins
Create the app
Log onto your Dokku Host to create the Plausible app:
dokku apps:create plausible
Add plugins
Install, create and link PostgreSQL and Clickhouse plugins:
# Install plugins on Dokku
dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku plugin:install https://github.com/dokku/dokku-clickhouse.git clickhouse
# Create running plugins
dokku postgres:create plausible -I 12
dokku clickhouse:create plausible -I 21.3.2.5
# Link plugins to the main app
dokku postgres:link plausible plausible
dokku clickhouse:link plausible plausible
Configuration
Add CLICKHOUSE_DATABASE_URL to environment variables
# Show all enironement variables to copy content of CLICKHOUSE_URL variable
dokku config plausible
Transform CLICKHOUSE_URL to http format like (as example) :
clickhouse://plausible:password@dokku-clickhouse-plausible:9000/plausible
Become (scheme and port change):
http://plausible:password@dokku-clickhouse-plausible:8123/plausible
# Set CLICKHOUSE_DATABASE_URL
dokku config:set plausible CLICKHOUSE_DATABASE_URL='http://plausible:password@dokku-clickhouse-plausible:8123/plausible'
Setting up secret key
dokku config:set plausible SECRET_KEY_BASE=$(openssl rand -hex 64)
Setting up BASE_URL
dokku config:set plausible BASE_URL=https://plausible.example.com
Setting up smtp information
dokku config:set plausible [email protected] \
SMTP_HOST_ADDR=mail.example.com \
SMTP_HOST_PORT=465 \
[email protected] \
SMTP_USER_PWD=example1234 \
SMTP_HOST_SSL_ENABLED=true
Setting up first admin information
dokku config:set plausible [email protected] \
ADMIN_USER_NAME=admin \
ADMIN_USER_PWD=admin1234
Disable registration (optional)
dokku config:set plausible DISABLE_REGISTRATION=true
Domain setup
To get the routing working, we need to apply a few settings. First we set the domain.
dokku domains:set plausible plausible.example.com
Push Plausible to Dokku
Grabbing the repository
First clone this repository onto your machine.
Via SSH
git clone [email protected]:D1ceWard/plausible_on_dokku.git
Via HTTPS
git clone https://github.com/D1ceWard/plausible_on_dokku.git
Set up git remote
Now you need to set up your Dokku server as a remote.
git remote add dokku [email protected]:plausible
Push Plausible
Now we can push Plausible to Dokku (before moving on to the next part).
git push dokku master
SSL certificate
Last but not least, we can go an grab the SSL certificate from Let's Encrypt.
# Install letsencrypt plugin
dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
# Set certificate contact email
dokku config:set --no-restart plausible [email protected]
# Generate certificate
dokku letsencrypt plausible
Wrapping up
Your Plausible instance should now be available on https://plausible.example.com.
Bonus: rename script file
By default, Plausible will use a file called /js/plausible.js
which is blocked by most adblockers (Adblock business lets you pay to display your ads, but privacy-focused analytics are blocked by default. Yay).
Since Plausible respects user privacy, it seems fair to collect anonymous traffic data. You can add a nginx config file: vi /home/dokku/plausible/nginx.conf.d/rewrite.conf
:
rewrite ^/js/pls.js$ /js/plausible.js last;
Rename pls.js
to whatever fits your need, and use this file name from now on.