How to Self-Host Plausible Analytics on a $6 VPS

by David Park
How to Self-Host Plausible Analytics on a $6 VPS

You'll end up with a fully functional Plausible Analytics instance running on a single $6 Hetzner CAX11 (or equivalent) VPS, fronted by Caddy for automatic TLS, persisting data to a local ClickHouse volume. No third-party analytics bill, no GDPR consent banners required, and full ownership of your visitor data.

Prerequisites

  • A VPS running Ubuntu 24.04 LTS with at least 1 vCPU and 2 GB RAM (Hetzner CAX11 at €3.79/mo works; DigitalOcean Basic $6/mo works)
  • A domain or subdomain pointed at the VPS IP via an A record — e.g. stats.example.com
  • SSH access as root or a sudo user
  • Ports 80 and 443 open in your firewall
  • Basic familiarity with the terminal and systemctl

Step 1 — Update the System and Install Docker

Run the system update first so you start from a clean package state.

apt update && apt upgrade -y

Install Docker's official GPG key and repository, then install Docker Engine and the Compose plugin.

apt install -y ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
  | tee /etc/apt/sources.list.d/docker.list > /dev/null

apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify Docker is running.

docker version

Expected output (versions will differ slightly):

Client: Docker Engine - Community
 Version:           26.1.4
...
Server: Docker Engine - Community
 Engine:
  Version:          26.1.4

Step 2 — Create the Plausible Directory and Configuration Files

Create a dedicated directory to keep all Plausible files together.

mkdir -p /opt/plausible && cd /opt/plausible

Create the required environment file. Replace every placeholder in angle brackets before saving.

cat > plausible-conf.env << 'EOF'
BASE_URL=https://stats.example.com
SECRET_KEY_BASE=<run: openssl rand -base64 48>
TOTPVAULT_KEY=<run: openssl rand -base64 32>
DISABLE_REGISTRATION=true
EOF

Generate the two secret values now and paste them into the file.

openssl rand -base64 48   # paste as SECRET_KEY_BASE
openssl rand -base64 32   # paste as TOTP_VAULT_KEY

Open the file with your editor and replace the placeholders.

nano /opt/plausible/plausible-conf.env

Setting DISABLE_REGISTRATION=true means only you can create an account — do the initial signup before enabling this, or set it to invite_only if you want to invite teammates later.

Step 3 — Write the Docker Compose File

Create the Compose file that defines Plausible, ClickHouse, and PostgreSQL.

cat > /opt/plausible/docker-compose.yml << 'EOF'
version: "3.8"

services:
  plausible_db:
    image: postgres:16-alpine
    restart: always
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

  plausible_events_db:
    image: clickhouse/clickhouse-server:24.3-alpine
    restart: always
    volumes:
      - event-data:/var/lib/clickhouse
      - ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
      - ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
    ulimits:
      nofile:
        soft: 262144
        hard: 262144

  plausible:
    image: ghcr.io/plausible/community-edition:v2.1.1
    restart: always
    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
    depends_on:
      plausible_db:
        condition: service_healthy
      plausible_events_db:
        condition: service_started
    env_file:
      - plausible-conf.env
    environment:
      - DATABASE_URL=postgres://postgres:postgres@plausible_db:5432/plausible_db
      - CLICKHOUSE_DATABASE_URL=http://plausible_events_db:8123/plausible_events
    ports:
      - "127.0.0.1:8000:8000"

volumes:
  db-data:
  event-data:
EOF

Pinning ghcr.io/plausible/community-edition:v2.1.1 prevents surprise breaking changes on container restart. Check github.com/plausible/analytics/releases for the latest tag and update accordingly.

Create the ClickHouse logging config files that suppress verbose output (saves disk on a small VPS).

mkdir -p /opt/plausible/clickhouse

cat > /opt/plausible/clickhouse/clickhouse-config.xml << 'EOF'
<clickhouse>
  <logger>
    <level>warning</level>
    <console>true</console>
  </logger>
  <query_thread_log remove="remove"/>
  <query_log remove="remove"/>
  <text_log remove="remove"/>
  <trace_log remove="remove"/>
  <metric_log remove="remove"/>
  <asynchronous_metric_log remove="remove"/>
  <session_log remove="remove"/>
  <part_log remove="remove"/>
</clickhouse>
EOF

cat > /opt/plausible/clickhouse/clickhouse-user-config.xml << 'EOF'
<clickhouse>
  <profiles>
    <default>
      <log_queries>0</log_queries>
      <log_query_threads>0</log_query_threads>
    </default>
  </profiles>
</clickhouse>
EOF

Step 4 — Install Caddy and Configure the Reverse Proxy

Caddy handles TLS automatically via Let's Encrypt — no Certbot cron jobs required.

apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
  | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
  | tee /etc/apt/sources.list.d/caddy-stable.list
apt update && apt install -y caddy

Write the Caddyfile. Replace stats.example.com with your actual subdomain.

cat > /etc/caddy/Caddyfile << 'EOF'
stats.example.com {
    reverse_proxy localhost:8000
    encode gzip
    header {
        Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
        X-Content-Type-Options nosniff
        X-Frame-Options DENY
        Referrer-Policy strict-origin-when-cross-origin
    }
}
EOF

Reload Caddy to apply the configuration.

systemctl reload caddy

Step 5 — Start Plausible and Create Your Admin Account

Bring up all containers in detached mode.

cd /opt/plausible && docker compose up -d

Watch the logs until the Plausible container reports it is listening.

docker compose logs -f plausible

Expected output (wait up to 60 seconds for migrations):

plausible-plausible-1  | [info] Running PlausibleWeb.Endpoint with cowboy 2.10.0 at 0.0.0.0:8000

Press Ctrl+C to stop following logs.

Open https://stats.example.com in your browser. You'll see the Plausible registration page. Create your admin account now — then set DISABLE_REGISTRATION=true in plausible-conf.env and run:

docker compose up -d plausible

This restarts only the Plausible container, picking up the new env value without touching the databases.

Verify It Works

Run these checks in order.

1. Confirm all three containers are running:

docker compose -f /opt/plausible/docker-compose.yml ps

Expected: plausible_db, plausible_events_db, and plausible all show running.

2. Confirm Caddy obtained a TLS certificate:

curl -I https://stats.example.com

Expected: HTTP/2 200 and no certificate warnings.

3. Confirm the tracking script loads:

curl -s https://stats.example.com/js/script.js | head -1

Expected: minified JavaScript starting with !function().

4. Check Caddy's systemd status:

systemctl status caddy

Expected: active (running).

Troubleshooting

Plausible container exits immediately Run docker compose logs plausible and look for database connection errors. The sleep 10 in the Compose command buys time, but on a slow VPS PostgreSQL may still not be ready. Increase the sleep to 20 and restart.

TLS certificate not issued Verify the A record has propagated: dig +short stats.example.com. Caddy logs are at journalctl -u caddy -n 50. Common cause: port 80 blocked by a cloud firewall rule (Hetzner Firewall, UFW, etc.).

ClickHouse keeps restarting Check docker compose logs plausible_events_db. The most common cause on 1 GB RAM machines is the nofile ulimit not applying. Confirm with docker inspect plausible-plausible_events_db-1 | grep -A4 Ulimits.

"Registration disabled" on first visit You set DISABLE_REGISTRATION=true before creating your account. Set it back to false, restart the container, register, then re-disable.

Disk filling up faster than expected ClickHouse retains raw event data indefinitely by default. Add a retention policy in the Plausible admin UI under Settings → Data Retention to cap storage.

Caddy returns 502 Bad Gateway Plausible is not yet listening. Run docker compose ps — if the plausible container is still starting, wait 30 seconds and retry. If it has exited, check logs as above.

Next Steps

Once the stack is stable, consider these additions:

  • Automated backups: Schedule a daily pg_dump and copy the ClickHouse /var/lib/clickhouse volume to Hetzner Object Storage (S3-compatible, €0.023/GB) using rclone.
  • Monitoring: Add an uptime check with a free Uptime Robot monitor pointed at https://stats.example.com/js/script.js.
  • Update strategy: Pin a new image tag in docker-compose.yml, run docker compose pull && docker compose up -d, and keep the old image cached with docker image ls until you confirm the new version is stable.
  • Embed the tracking snippet: In your Plausible dashboard, go to Settings → Installation and copy the one-line <script> tag into your site's <head>.

Running Plausible self-hosted on a $6 VPS eliminates a $9–$19/month SaaS bill, keeps visitor data on infrastructure you control, and requires no GDPR consent mechanism for cookieless tracking. The entire stack — Plausible, ClickHouse, PostgreSQL, and Caddy — idles comfortably under 1.2 GB RAM on a Hetzner CAX11.