Self-Hosting Plausible Analytics With Dokku
In my search for a self-hosted alternative to Google Analytics, I found Plausible Analytics. Plausible is an open-source and privacy focused alternative to Google Analytics, which I wanted to remove entirely from my sites. Self-hosting with the instructions from their documentation is not geared towards someone trying to host it on a Dokku host. This guide will help walk you through the steps of setting up Plausible on a Dokku host. We will create the application, install the required plugins, create all the necessary databases, link them to the application, and deploy the application.
What is Dokku?
Dokku is a popular, open-source, and self-hosted platform as a service (PaaS) that allows users to easily deploy and manage their applications, very similar to your own self-hosted Heroku. Under the hood, Dokku is powered by Docker, uses Heroku buildpacks by default, and has a number of official and community plugins.
There is a one-click install image you can use from Digital Ocean, but I personally like to start with a fresh box and enjoy installing and configuring it all myself.
The only system requirements are 1GB of memory and either Ubuntu 18.04/20.04 x64, Debian 9+ x64, or CentOS 7 x64.
You can read more about using Dokku in my blog post yesterday.
What is Plausible?
Plausible is an open-source and privacy focused alternative to Google Analytics. It uses no cookies and is fully compliant with GDPR, CCPA, and PECR. While it is easiest to just pay the $6 / per month for a cloud hosted instance, I will always choose self-hosted if it is an option and here is no exception. Self-hosting with the instructions from their documentation is not geared towards someone trying to host it on Dokku. Because of it, I wanted to document the process in hopes of helping others set up their own instance of Plausible.
The only requirement is a working Dokku host.
We are going to use the domain analytics.example.com
for demonstration purposes. Be sure to replace it with your own domain name when running through the bash command snippets.
First, we're going to SSH into your Dokku Host and create the Plausible app:
Next, we will install the PostgreSQL and Clickhouse plugins, if they aren't already installed.
And then, we'll create our instances of the PostgresSQL and Clickhouse databases.
Let's then set the environment variables for the database scheme, which just sets it to use the scheme expected within the Plausible Docker image. Then we'll link the databases to the application.
Next, we'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.
Then, we'll generate a secrete key using openssl
.
And then, we'll set the BASE_URL
environment variable and set the domain for the application — make sure to use your domain here.
Set the required SMTP environment variables to set up transactional emails.
Let's set up our admin account for the application. And then, we can optionally disable registration, this is especially useful if this is just for you and you aren't inviting any clients or other users to utilize it.
Next, we need to clone (or fork!) the my repository on your local machine.
Set the Dokku host as the git remote for the repository and push it on up to your Dokku host!
After the initial push and deploy, we can then finally set up the SSL certificate from Let's Encrypt.
Let's start by installing the Let's Encrypt plugin, if you don't already have it installed.
Then we can set the certificate contact email.
And finally, generate the certificates!
At this point your instance of Plausible should be accessible via, the domain your provided, which for us is https://analytics.example.com.
Profit!!! 🎉🎉🎉