Blog post illustration

Deploy PostHog on Dokku

August 27, 2021 3 min read

This guide can also be found directly in the dokku-posthog Github repository.

What is PostHog?

PostHog is an open-source product analytics suite, built for developers. Automate the collection of every event on your website or app, with no need to send data to 3rd parties.

What is Dokku?

Dokku is the smallest PaaS implementation you've ever seen



Note: We are going to use the domain for demonstration purposes. Make sure to replace it with your own domain name.

App and plugins

Create the app

Log onto your Dokku Host to create the PostHog app:

dokku apps:create posthog

Add plugins

Install, create and link PostgreSQL plugin:

# Install plugins
dokku plugin:install postgres
dokku plugin:install redis
# Create running plugins
dokku postgres:create posthog
dokku redis:create posthog
# Link plugins to the main app
dokku postgres:link posthog posthog
dokku redis:link posthog posthog

Configure dokku app

Environment variables

dokku config:set posthog POSTGRES_DB=posthog POSTGRES_PASSWORD=<...> POSTGRES_USER=postgres SECRET_KEY=<...>


Extract password from existing

# Show all enironement variables to copy content of DATABASE_URL variable
dokku config posthog

Copy the password from DATABASE_URL

dokku config:set posthog POSTGRES_DB=posthog POSTGRES_PASSWORD=<found in DATABSE_URL>

Web app

dokku config:set posthog SECRET_KEY=<randomly generated secret key> SITE_URL= IS_BEHIND_PROXY=True DISABLE_SECURE_SSL_REDIRECT=True

Set up the domain

To get the routing working, we need to apply a few settings. First we set the domain.

dokku domains:set posthog

Then we set the ports to redirect to

dokku proxy:ports-set posthog http:80:8000 https:443:8000

Push PostHog to Dokku

  1. Clone the dokku-posthog repository.

  2. Set up your Dokku server as a remote.

    git remote add dokku
  3. Push it to Dokku

    git push dokku master

Add SSL certificate (to enable HTTPS)

Last but not least, we can go an grab the SSL certificate from Let's Encrypt.

# Install letsencrypt plugin
dokku plugin:install

# Set certificate contact email
dokku config:set --no-restart posthog

# Generate certificate
dokku letsencrypt posthog

Wrapping up

Your PostHog instance should now be available on