Self hosting Plausible with Caprover

Reading time:   2 min

self-hosting-plausible-with-caprover

Plausible Analytics is a simple and privacy-friendly alternative to Google Analytics.

They offer a free Plausible Analytics Self-Hosted, that it’s exactly the same code as their Cloud solution, but you have to install on your server.

As a fan of Caprover, that I use everyday to manage my web applications, and after looking at the official Caprover repository for one-click apps, I found that Plausible was missing, so I decided to write the template.

On their offical repository there is a docker-compose.yml file that I used as starting point to transform in a one-click Caprover app, but the GeoLite2 database created by MaxMind for enriching analytics data with visitor countries was not present.

So, looking at the self hosted guides available in their documentation, I came up with a plausible.yml template:

captainVersion: 4
services:
$$cap_appname-mail:
image: bytemark/smtp
restart: always
environment:
RELAY_HOST: $$cap_RELAY_HOST
RELAY_PORT: $$cap_RELAY_PORT
RELAY_USERNAME: $$cap_RELAY_USERNAME
RELAY_PASSWORD: $$cap_RELAY_PASSWORD
caproverExtra:
notExposeAsWebApp: "true"
$$cap_appname-postgres:
image: postgres:12-alpine
volumes:
- $$cap_appname-postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: plausible
POSTGRES_PASSWORD: $$cap_POSTGRES_PASSWORD
caproverExtra:
notExposeAsWebApp: "true"
$$cap_appname-clickhouse:
image: yandex/clickhouse-server:20.8.5.45
volumes:
- $$cap_appname-clickhouse-data:/var/lib/clickhouse
caproverExtra:
notExposeAsWebApp: "true"
$$cap_appname-geoip:
image: maxmindinc/geoipupdate:v4.5
environment:
GEOIPUPDATE_ACCOUNT_ID: $$cap_GEOIPUPDATE_ACCOUNT_ID
GEOIPUPDATE_LICENSE_KEY: $$cap_GEOIPUPDATE_LICENSE_KEY
GEOIPUPDATE_EDITION_IDS: GeoLite2-Country
GEOIPUPDATE_FREQUENCY: 168
volumes:
- $$cap_appname-geoip-data:/usr/share/GeoIP
$$cap_appname:
depends_on:
- $$cap_appname-postgres
- $$cap_appname-clickhouse
- $$cap_appname-mail
caproverExtra:
containerHttpPort: "8000"
dockerfileLines:
- FROM plausible/analytics:v1.1.1
- CMD ["sh", "-c", "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"]
environment:
ADMIN_USER_EMAIL: $$cap_ADMIN_USER_EMAIL
ADMIN_USER_NAME: $$cap_ADMIN_USER_NAME
ADMIN_USER_PWD: $$cap_ADMIN_USER_PWD
BASE_URL: http://$$cap_appname.$$cap_root_domain
DATABASE_URL: postgres://plausible:$$cap_POSTGRES_PASSWORD@srv-captain--$$cap_appname-postgres:5432/plausible
CLICKHOUSE_DATABASE_URL: http://srv-captain--$$cap_appname-clickhouse:8123/plausible
SECRET_KEY_BASE: $$cap_gen_random_hex(64)
SIGNING_SALT: $$cap_gen_random_hex(24)
DISABLE_REGISTRATION: "true"
DISABLE_SUBSCRIPTION: "true"
MAILER_EMAIL: $$cap_RELAY_USERNAME
SMTP_HOST_ADDR: srv-captain--$$cap_appname-mail
SMTP_HOST_PORT: "25"
GEOLITE2_COUNTRY_DB: "/geoip/GeoLite2-Country.mmdb"
volumes:
- $$cap_appname-geoip-data:/geoip
caproverOneClickApp:
variables:
- defaultValue: "[email protected]"
description: This is the admin email. Please change it.
id: $$cap_ADMIN_USER_EMAIL
label: ADMIN_USER_EMAIL
validRegex: /^([^\s^\/])+$/
- defaultValue: "admin"
description: This is the admin username. Please change it.
id: $$cap_ADMIN_USER_NAME
label: ADMIN_USER_NAME
validRegex: /^([^\s^\/])+$/
- defaultValue: "password"
description: This is the admin password. Please change it.
id: $$cap_ADMIN_USER_PWD
label: ADMIN_USER_PWD
validRegex: /^([^\s^\/])+$/
- defaultValue: "plausible"
description: This is the PostgreSQL password for user 'plausible'. Please change it.
id: $$cap_POSTGRES_PASSWORD
label: POSTGRES_PASSWORD
validRegex: /^([^\s^\/])+$/
- defaultValue: "smtp.mailgun.org"
description: This is the SMTP host for sending email. Use Mailgun or whatever other service.
id: $$cap_RELAY_HOST
label: RELAY_HOST
validRegex: /^([^\s^\/])+$/
- defaultValue: "587"
description: This is the port for the SMTP host. Please change it if needed.
id: $$cap_RELAY_PORT
label: RELAY_PORT
validRegex: /^([^\s^\/])+$/
- description: This is the username for logging into the SMTP host. Please change it according to your host.
id: $$cap_RELAY_USERNAME
label: RELAY_USERNAME
validRegex: /^([^\s^\/])+$/
- description: This is the password for logging into the SMTP host. Please change it according to your host.
id: $$cap_RELAY_PASSWORD
label: RELAY_PASSWORD
validRegex: /^([^\s^\/])+$/
- description: Provide your own ACCOUNT_ID, you can sign-up at https://www.maxmind.com/en/geoip2-services-and-databases
id: $$cap_GEOIPUPDATE_ACCOUNT_ID
label: GEOIPUPDATE_ACCOUNT_ID
validRegex: /^([^\s^\/])+$/
- description: Provide the corresponding License Key for your own ACCOUNT_ID.
id: $$cap_GEOIPUPDATE_LICENSE_KEY
label: GEOIPUPDATE_LICENSE_KEY
validRegex: /^([^\s^\/])+$/
instructions:
start: >-
Plausible is a lightweight and open-source website analytics tool.
It doesn’t use cookies and is fully compliant with GDPR, CCPA and PECR. Made and hosted in the EU.
This one click app uses the:
- official image from https://hub.docker.com/r/plausible/analytics
- https://hub.docker.com/r/bytemark/smtp, that allows linked containers to send outgoing email
- official PostgreSQL image based on Alpine Linux
- ClickHouse image https://hub.docker.com/r/yandex/clickhouse-server, an open-source column-oriented database
- official image from https://hub.docker.com/r/maxmindinc/geoipupdate, the well known MaxMind GeoIP Update Tool.
end: >-
Plausible.io is deployed and available as $$cap_appname.
In case you add a new domain to your application, remember to set the environment variable BASE_URL accordingly.
IMPORTANT: It will take up to 2 minutes for Plausible to be ready. Before that, you might see 502 error page.
displayName: Plausible
isOfficial: false
description: Plausible is a lightweight and open-source website analytics tool.
documentation: Taken from https://plausible.io/.
view raw plausible.yml hosted with ❤ by GitHub

Simply copy and paste this template in Caprover, and you'll have a Plausible.io self hosted analytics application up and running!

Then follow their guide to add your first website, and copy the automatically generated snippet in the <head> tag of your website.

EDIT: as if today, 31/10/2020, the Plausible template is already available in the official repository. Simply search for the app inside Caprover installation:

Select an app name - can be plausible 😀 - and deploy!

Sounds interesting ?

Contact me to discuss your need.

Thomas Cenni
Thomas Cenni is an Electronic Engineer with more than 20 years of experience in program management and software engineering. Passionate about software engineering and development, experienced leader with a strong background in the end-to-end lifecycle of product development, he is also a certified SAFe® 6 agilist. Entrepreneur, credible and highly motivated, he showed a great ability to adapt to various cultures and countries, assuming different roles and challenges in Italy, Brazil and France. He is fluent in English, French, Italian and Brazilian Portuguese.