Skip to Content

Deploy PostHog

🦔 PostHog is an all-in-one developer platform for building successful products. We offer product analytics, web analytics, session replay, error tracking, feature flags, experimentation, surveys, data warehouse, a CDP, and an AI product assistant to help debug your code, ship features faster, and keep all your usage and customer data in one stack.

⭐ 31.2k stars📜 Other🔴 Advanced⏱ ~20 minutes

What You’ll Get

A fully working PostHog instance running on your server. Your data stays on your hardware — no third-party access, no usage limits, no surprise invoices.

Prerequisites

  • A server with Docker and Docker Compose installed (setup guide)
  • A domain name pointed to your server (optional but recommended)
  • Basic terminal access (SSH)

The Config

Create a directory for PostHog and add this docker-compose.yml:

# ------------------------------------------------------------------------- # 🚀 Created and distributed by The AltStack # 🌍 https://thealtstack.com # ------------------------------------------------------------------------- version: '3.8' services: db: image: postgres:14-alpine container_name: posthog-db restart: unless-stopped environment: - POSTGRES_PASSWORD=posthog - POSTGRES_DB=posthog - POSTGRES_USER=posthog volumes: - posthog_postgres_data:/var/lib/postgresql/data redis: image: redis:6-alpine container_name: posthog-redis restart: unless-stopped volumes: - posthog_redis_data:/data clickhouse: image: clickhouse/clickhouse-server:22.3-alpine container_name: posthog-clickhouse restart: unless-stopped environment: - CLICKHOUSE_DB=posthog - CLICKHOUSE_USER=default - CLICKHOUSE_PASSWORD= volumes: - posthog_clickhouse_data:/var/lib/clickhouse kafka: image: confluentinc/cp-kafka:7.5.3 container_name: posthog-kafka restart: unless-stopped depends_on: - zookeeper environment: - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 zookeeper: image: confluentinc/cp-zookeeper:7.5.3 container_name: posthog-zookeeper restart: unless-stopped environment: - ZOOKEEPER_CLIENT_PORT=2181 - ZOOKEEPER_TICK_TIME=2000 posthog: image: posthog/posthog:release-1.40.0 container_name: posthog restart: unless-stopped depends_on: - db - redis - clickhouse - kafka ports: - "8000:8000" environment: - DATABASE_URL=postgres://posthog:posthog@db:5432/posthog - REDIS_URL=redis://redis:6379/ - CLICKHOUSE_HOST=clickhouse - KAFKA_HOSTS=kafka:9092 - SECRET_KEY=please-change-this-secret-key-in-production-12345 - SKIP_SERVICE_VERSION_REQUIREMENTS=1 volumes: - ./uploads:/app/static/uploads volumes: posthog_postgres_data: posthog_redis_data: posthog_clickhouse_data:

Let’s Ship It

# Create a directory mkdir -p /opt/posthog && cd /opt/posthog # Create the docker-compose.yml (paste the config above) nano docker-compose.yml # Pull images and start docker compose up -d # Watch the logs docker compose logs -f

Environment Variables

VariableDefaultRequired
POSTGRES_PASSWORDposthogNo
POSTGRES_DBposthogNo
POSTGRES_USERposthogNo
CLICKHOUSE_DBposthogNo
CLICKHOUSE_USERdefaultNo
KAFKA_ZOOKEEPER_CONNECTzookeeper:2181No
KAFKA_ADVERTISED_LISTENERSPLAINTEXT://kafka:9092No
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR1No
ZOOKEEPER_CLIENT_PORT2181No
ZOOKEEPER_TICK_TIME2000No
DATABASE_URLpostgres://posthog:posthog@db:5432/posthogNo
REDIS_URLredis://redis:6379/No
CLICKHOUSE_HOSTclickhouseNo
KAFKA_HOSTSkafka:9092No
SECRET_KEYplease-change-this-secret-key-in-production-12345No
SKIP_SERVICE_VERSION_REQUIREMENTS1No

Post-Deployment Checklist

  • Service is accessible on the configured port
  • Admin account created (if applicable)
  • Reverse proxy configured (Caddy guide)
  • SSL/HTTPS working
  • Backup script set up (backup guide)
  • Uptime monitor added (Uptime Kuma)

The “I Broke It” Section

Container won’t start?

docker compose logs posthog | tail -50

Port already in use?

# Find what's using the port lsof -i :PORT_NUMBER

Need to start fresh?

docker compose down -v # ⚠️ This deletes volumes/data! docker compose up -d

Going Further