August 27, 2021 • 3 min read
This guide can also be found directly in the dokku-posthog Github repository.
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.
Dokku is the smallest PaaS implementation you've ever seen
Note: We are going to use the domain posthog.example.com
for demonstration purposes. Make sure to replace it with your own domain name.
Log onto your Dokku Host to create the PostHog app:
dokku apps:create posthog
Install, create and link PostgreSQL plugin:
# Install plugins
dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku plugin:install https://github.com/dokku/dokku-redis.git 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
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>
dokku config:set posthog SECRET_KEY=<randomly generated secret key> SITE_URL=https://posthog.example.com IS_BEHIND_PROXY=True DISABLE_SECURE_SSL_REDIRECT=True
To get the routing working, we need to apply a few settings. First we set the domain.
dokku domains:set posthog posthog.example.com
Then we set the ports to redirect to
dokku proxy:ports-set posthog http:80:8000 https:443:8000
Clone the dokku-posthog repository.
Set up your Dokku server as a remote.
git remote add dokku dokku@example.com:posthog
Push it to Dokku
git push dokku master
Last but not least, we can go an grab the SSL certificate from Let's Encrypt.
# Install letsencrypt plugin
dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
# Set certificate contact email
dokku config:set --no-restart posthog DOKKU_LETSENCRYPT_EMAIL=you@example.com
# Generate certificate
dokku letsencrypt posthog
Your PostHog instance should now be available on https://posthog.example.com.