---
title: "Deploy PostHog"
description: "Self-hosted PostHog: product analytics, replay, flags, surveys"
category: "Analytics"
url: https://railway.com/deploy/posthog
---

# Deploy PostHog

Self-hosted PostHog: product analytics, replay, flags, surveys

**[Deploy PostHog on Railway](https://railway.com/template/posthog)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/posthog/manifest.json

- **Creator:** My Projects
- **Category:** Analytics

## Template content

### Storage https://cdn.jsdelivr.net/gh/selfhst/icons/svg/seaweedfs.svg

- **Image:** chrislusf/seaweedfs:4.29
- **Start command:** `/bin/sh -c 'printenv STORAGE_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`

### PersonHog Router https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/personhog-router:sha-99e258d

### ZooKeeper https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** zookeeper:3.7.0
- **Start command:** `/bin/sh -c 'rm -rf /data/lost+found; mkdir -p /data/data /data/datalog; chown -R zookeeper:zookeeper /data; exec /docker-entrypoint.sh zkServer.sh start-foreground'`

### PostHog https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** caddy:2.10.2-alpine
- **Start command:** `/bin/sh -c 'printenv PROXY_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`
- **Health check:** /proxy-health
- **Public domain:** Yes

### Temporal https://cdn.simpleicons.org/temporal

- **Image:** temporalio/auto-setup:1.29.7

### Ingestion https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog-node:sha-1a3b1f82566f2fa562aaf96c7e394239cab61ba9
- **Start command:** `/bin/sh -c 'printenv NODE_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:15

### Replay Ingestion https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog-node:sha-1a3b1f82566f2fa562aaf96c7e394239cab61ba9
- **Start command:** `/bin/sh -c 'printenv NODE_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`

### Recording API https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog-node:sha-1a3b1f82566f2fa562aaf96c7e394239cab61ba9
- **Start command:** `/bin/sh -c 'printenv NODE_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`

### Worker https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** posthog/posthog:sha-1a3b1f82566f2fa562aaf96c7e394239cab61ba9
- **Start command:** `./bin/docker-worker-celery --with-scheduler`

### Property Defs https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/property-defs-rs:sha-99e258d

### Hypercache https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/hypercache-server:sha-99e258d

### Redis https://devicons.railway.app/i/redis.svg

- **Image:** redis:7.2-alpine
- **Start command:** `/bin/sh -c 'rm -rf /data/lost+found; exec redis-server --dir /data --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru'`

### ClickHouse https://cdn.jsdelivr.net/gh/selfhst/icons/svg/clickhouse.svg

- **Image:** ghcr.io/posthog/clickhouse-posthog:26.9.5.2-posthog-aca5bdabb92f
- **Start command:** `/bin/bash -c 'printenv CLICKHOUSE_RUN_SH > /tmp/run.sh && exec bash /tmp/run.sh'`

### Capture https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/capture:sha-99e258d

### Kafka https://cdn.simpleicons.org/apachekafka

- **Image:** redpandadata/redpanda:v25.1.9
- **Start command:** `/bin/sh -c 'printenv KAFKA_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`

### Temporal Worker https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** posthog/posthog:sha-1a3b1f82566f2fa562aaf96c7e394239cab61ba9
- **Start command:** `./bin/temporal-django-worker`

### Feature Flags https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/feature-flags:sha-99e258d

### Livestream https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/livestream:sha-7ca4279acf0843fc331ac2176fe2e03809b604d2
- **Start command:** `/bin/sh -c 'mkdir -p /configs && printenv LIVESTREAM_CONFIG > /configs/configs.yml && exec /livestream'`

### Replay Capture https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/capture:sha-99e258d

### Plugins https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog-node:sha-1a3b1f82566f2fa562aaf96c7e394239cab61ba9
- **Start command:** `/bin/sh -c 'printenv NODE_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`

### Web https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** posthog/posthog:sha-1a3b1f82566f2fa562aaf96c7e394239cab61ba9
- **Start command:** `/bin/sh -c 'printenv WEB_RUN_SH > /tmp/run.sh && exec sh /tmp/run.sh'`
- **Health check:** /_health

### PersonHog Replica https://cdn.jsdelivr.net/gh/selfhst/icons/svg/posthog.svg

- **Image:** ghcr.io/posthog/posthog/personhog-replica:sha-99e258d

## Documentation

# Deploy and Host PostHog on Railway

PostHog is an open-source product analytics platform, an alternative to Mixpanel, Amplitude, Hotjar and LaunchDarkly in one tool. It records events from your website and apps, and gives you trends, funnels, retention, user paths, session replay, feature flags, A/B experiments, surveys and a SQL editor over your own data.

## About Hosting PostHog

Self-hosted PostHog is a large system. Events come in through a capture service, pass through Kafka to an ingestion pipeline that resolves people and properties, and land in ClickHouse, where every chart is queried. Postgres holds the app data, Redis caches, Temporal and Celery run background jobs, and S3 storage keeps session recordings and exports. ClickHouse needs PostHog's own configuration, Kafka topics must exist before consumers start, and a fresh instance lets the first visitor sign up as the owner.

This template runs PostHog's official images as 23 services behind one public Caddy entry point, the same routing PostHog's Docker setup uses. It creates your admin account at deploy, configures ClickHouse, Kafka and storage for Railway's private network, and pins every image to one tested PostHog commit.

## Common Use Cases

- Product analytics for a web or mobile app: trends, funnels, retention, paths
- Session replay to watch how users move through your product
- Feature flags and A/B experiments without a separate service
- A Mixpanel, Amplitude or Hotjar replacement that keeps event data on your own infrastructure
- In-app surveys and a SQL editor over raw events

## Dependencies for PostHog Hosting

- ClickHouse 26.9 (PostHog build), Kafka API (Redpanda 25.1), ZooKeeper 3.7
- PostgreSQL 15, Redis 7.2, S3 storage (SeaweedFS)
- Temporal 1.29

### Deployment Dependencies

- PostHog: https://github.com/PostHog/posthog
- Self-hosting docs: https://posthog.com/docs/self-host
- Docker setup this template follows: https://github.com/PostHog/posthog/blob/master/docker-compose.hobby.yml

### Implementation Details

**What you set:** `POSTHOG_ADMIN_EMAIL`, the email you log in with. Optionally `POSTHOG_ORGANIZATION_NAME`.

**After deploy:**

1. Wait for the first start: Web runs PostHog's migrations, about 30 minutes. Its logs show `posthog-setup: starting web server` when ready.
2. Open the PostHog URL and log in with `POSTHOG_ADMIN_EMAIL` and the generated `POSTHOG_ADMIN_PASSWORD` (Web service → Variables).
3. Copy the project API key from Settings → Project and add the snippet to your site, with `api_host` set to your PostHog URL.

**This template:**

- Creates the admin at deploy, so no visitor can claim your instance; new organizations can't be created after that
- Exposes one public service; ClickHouse, Kafka, Postgres, Redis and storage stay private
- Generates the Django secret, encryption salt, storage keys and database password
- Configures ClickHouse from the same PostHog commit as the images, pre-creates Kafka topics, and prepares the plugin server's job queue database
- Includes session replay, feature flags, surveys, destinations and batch exports
- Leaves out error tracking symbolication, LLM analytics and logs capture, and heatmap screenshots (see the README)

**Notes:** PostHog needs a lot of resources. The services idle at about 15 GB of RAM together, so expect a larger Railway bill than a single app.

## Why Deploy PostHog on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying PostHog on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Plausible WordPress](https://railway.com/deploy/deploy-plausible-for-wordpress-sites) — Cookie-free WordPress stats from your own Plausible
- [Typesense Multilingual](https://railway.com/deploy/deploy-typesense-multilingual-search) — Locale-aware multilingual search with Typesense
- [Formbricks](https://railway.com/deploy/formbricks-surveys) — Surveys, NPS and in-app feedback on your own Postgres, Hub and Cube

Open this page in a browser: https://railway.com/deploy/posthog
