Henk Verlinde

Self-Hosting Plausible Analytics

· 1 min read

Super simple, robust, and secure setup for self-hosting Plausible Analytics on DigitalOcean.

Main components:

Services:

Provisioning

Create DigitalOcean droplet

  • Ubuntu 20.04 (LTS) x64
  • 1 CPU
  • 1 GB RAM
  • 25 GB NVMe SSDs
  • 1,000 GB transfer

See also: Recommended Initial Droplet Configuration

Upgrade installed packages

sudo apt update && sudo apt upgrade

Install Docker and Docker Compose

sudo apt install docker.io docker-compose

Clone plausible/hosting repo

git clone https://github.com/plausible/hosting && cd hosting

Configuration

Generate secret key

openssl rand -base64 64

Configure Plausible

nano plausible-conf.env
ADMIN_USER_NAME=<your-admin-user-name>
ADMIN_USER_EMAIL=<your-admin-user-email>
ADMIN_USER_PWD=<your-admin-user-password>
BASE_URL=<your-base-url>
SECRET_KEY_BASE=<your-secret-key-base>
DISABLE_REGISTRATION=true
MAILER_EMAIL=<your-mailer-email>
SMTP_HOST_ADDR=<your-smtp-host-address>
SMTP_USER_NAME=<your-smtp-user-name>
SMTP_USER_PWD=<your-smtp-user-password>
MAILER_ADAPTER=Bamboo.PostmarkAdapter
POSTMARK_API_KEY=<your-postmark-api-key>
GOOGLE_CLIENT_ID=<your-google-client-id>
GOOGLE_CLIENT_SECRET=<your-google-client-secret>

Configure Caddy

nano reverse-proxy/docker-compose.caddy-gen.yml
version: "3.3"
services:
  caddy-gen:
    container_name: caddy-gen
    image: "wemakeservices/caddy-gen:latest"
    restart: always
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - caddy-certificates:/data/caddy
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - plausible

  plausible:
    labels:
      virtual.host: "example.com" # change to your domain name
      virtual.port: "8000"
      virtual.tls-email: "admin@example.com" # change to your email

volumes:
    caddy-certificates:
        driver: local

Configure MaxMind

nano geoip/geoip.conf
GEOIPUPDATE_ACCOUNT_ID=<your-account-id>
GEOIPUPDATE_LICENSE_KEY=<your-license-key>

Add DNS record

  • Record type: A
  • Name: [subdomain]
  • Value: IPv4 address of DigitalOcean droplet

Add current user to docker group

sudo usermod -aG docker $USER

Running

Start server

docker-compose -f docker-compose.yml -f geoip/docker-compose.geoip.yml -f reverse-proxy/docker-compose.caddy-gen.yml up -d

View logs

docker logs -f hosting_plausible_1

Stop server

docker-compose down

Resources

Henk Verlinde