In this tutorial, we'll learn how to set up Plausible analytics on Ubuntu via Docker.
More developers and businesses are turning to Plausible Analytics as a clean, lightweight, and ethical alternative to Google Analytics. In this tutorial, we’ll walk through how to set up a fully self-hosted instance of Plausible Analytics on an Ubuntu 24.04 server using Docker and Docker Compose. This allows us to retain full ownership of our analytics data, comply with privacy laws like GDPR, and offer a transparent experience for our users.
Why Use Plausible Analytics?
Plausible is open-source and designed with simplicity and privacy in mind. Unlike traditional tools, it doesn’t use cookies or track personal data. By hosting Plausible ourselves, we gain:
- Full control over analytics data
- Lightweight, privacy-respecting JavaScript snippet
- No need for annoying cookie banners
- Transparent operations aligned with privacy laws
Prerequisites
Before we begin, let’s ensure our environment meets the following requirements:
- A Ubuntu 24.04 installed dedicated server or KVM VPS.
- A non-root user with sudo privileges.
- Basic knowledge of using the terminal.
Set up Plausible Analytics on Ubuntu via Docker
Step 1: Update Your Ubuntu Server
We start with a fresh Ubuntu 24.04 server. It's good practice to update the system before installing anything:
sudo apt update && sudo apt upgrade -y
Also install essential tools:
sudo apt install curl git unzip -y
Step 2: Configure Firewall
Before we proceed further, let's add HTTP and HTTPS ports in the firewall.
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
Step 3: Install Docker and Docker Compose
Plausible uses Docker to containerize services like the backend, frontend, database, and mail server.
Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Install Docker Compose:
sudo apt-get install docker-ce
Test installations:
docker --version
Step 4: Clone the Official Plausible Self-Hosting Repository
Plausible offers an official self-hosted setup via Docker Compose:
git clone -b v3.0.1 --single-branch https://github.com/plausible/community-edition plausible-ce
cd plausible-ce
This directory contains all the necessary Docker Compose files.
Step 5: Set Up Environment Variables
We now configure our .env file with secrets and details for our instance.
echo "BASE_URL=https://plausible.example.com" >> .env
echo "SECRET_KEY_BASE=$(openssl rand -base64 48)" >> .env
Make sure $BASE_URL
is set to the actual domain where you plan to host the service. The domain must have a DNS entry pointing to your server for proper resolution and automatic Let's Encrypt TLS certificate issuance. More on that in the next step.
Expose Plausible server to the web with a compose override file:
echo "HTTP_PORT=80" >> .env
echo "HTTPS_PORT=443" >> .env
Create compose.override.yml file
cat > compose.override.yml << EOF
services:
plausible:
ports:
- 80:80
- 443:443
EOF
Step 6: Launch Plausible
Now we’re ready to start the containers.
docker compose up -d
Check status:
docker compose ps
Docker will install SSL certificate automaticating. If all services are running, visit your domain:
https://plausible.example.com
Final Thoughts
In this tutorial, we've learnt how to set up Plausible analytics on Ubuntu via Docker. Plausible Analytics offers us a sustainable, privacy-first alternative to Google Analytics without sacrificing functionality. By self-hosting it on Ubuntu 24.04 using Docker, we gain full data control and contribute to a more ethical web.