Skip to content

PostHog Hobby (self-hosted) install

Created a directory /op/posthog into which downloaded and ran the Posthog install script from https://posthog.com/docs/self-host.

Following docs from https://posthog.com/docs/self-host didnt really work. The posthog-web-1 container kept on crashlooping. Checking the logs with 'docker logs revealed that the container misses a non-defaultSECRET_KEY` env variable.

For a list of env vars see: https://posthog.com/docs/self-host/configure/environment-variables

Another attempt to start Posthog was made like this:

  cd /opt/posthog
  export SITE_URL="https://posthog.ftmo.com"
  SECRET_KEY=`openssl rand -base64 30`
  docker-compose up

Problems persisted. Finally this comment solved the issue: https://github.com/PostHog/posthog/issues/16169#issuecomment-1794239573

Maintenance

To start or stop posthog, do cd /opt/posthog and use docker-compose up --detach or docker-compose down.

Afterwards check if all containers are running correctly using docker ps. This might take a while until all container boot up.

Debugging

If you notice anything similar in the docker ps output, it might be the container is crashlooping:

Restarting (1) 50 seconds ago```

In that case you must check what is wrong using `docker logs <CONTAINER_ID>`

## Zookeeper crashloop

Zookeper wouldnt start because of:
```ERROR [main:Util@166] - Last transaction was partial.```

The solution is to find the Zookeper datadir and delete the last log file with 0 size from the directory:

```bash
#docker volume list
DRIVER    VOLUME NAME
local     posthog_clickhouse-data
local     posthog_object_storage
local     posthog_postgres-data
local     posthog_zookeeper-data
local     posthog_zookeeper-datalog
local     posthog_zookeeper-logs

# docker volume inspect posthog_zookeeper-datalog
[
    {
        "CreatedAt": "2023-12-07T18:05:52+01:00",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "posthog",
            "com.docker.compose.version": "2.13.0",
            "com.docker.compose.volume": "zookeeper-datalog"
        },
        "Mountpoint": "/var/lib/docker/volumes/posthog_zookeeper-datalog/_data",
        "Name": "posthog_zookeeper-datalog",
        "Options": null,
        "Scope": "local"
    }
]

# cd /var/lib/docker/volumes/posthog_zookeeper-datalog/_data
Also see: https://stackoverflow.com/questions/44217654/how-to-recover-zookeeper-from-java-io-eofexception-after-a-server-crash