Install docker

Docker install

Install Plausible

1mkdir plausible
2git clone https://github.com/plausible/community-edition plausible/
3cd plausible
4mkdir db-data
5mkdir event-data
6mkdir event-logs

Set the docker-compose.yml file to contain the following. Note that the volumes are replaced by local folders for db-data​, event-data​, and event-logs​. Also, the plausible-npm​ network is created to make plausible a part of the NPM Docker. Since this setup communicates with NPM via plausible-npm​ network, there is no need for exposing the ports and so they are #ed​ out.

 1services:
 2  plausible_db:
 3    # Plausible v2.1.1 was tested against PostgreSQL versions 15 and 16
 4    # https://github.com/plausible/analytics/blob/v2.1.1/.github/workflows/elixir.yml#L21-L32
 5    image: postgres:16-alpine
 6    restart: always
 7    volumes:
 8      - ./db-data:/var/lib/postgresql/data
 9    environment:
10      - POSTGRES_PASSWORD=postgres
11    networks:
12      - plausible-net
13
14  plausible_events_db:
15    image: clickhouse/clickhouse-server:24.3.3.102-alpine
16    restart: always
17    volumes:
18      - ./event-data:/var/lib/clickhouse
19      - ./event-logs:/var/log/clickhouse-server
20      - ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
21      - ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
22    ulimits:
23      nofile:
24        soft: 262144
25        hard: 262144
26    networks:
27      - plausible-net
28
29  plausible:
30    image: ghcr.io/plausible/community-edition:v2.1.1
31    restart: always
32    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.>
33    depends_on:
34      - plausible_db
35      - plausible_events_db
36#    ports:
37#      - 127.0.0.1:8000:8000
38    env_file:
39      - plausible-conf.env
40    networks:
41      - plausible-net
42      - plausible-npm
43
44networks:
45  plausible-net:
46  plausible-npm:

Edit plausible-env.conf​ and set the values of all env variables in there. The secret keys can be generated by the command

# SECRET_KEY_BASE
openssl rand -base64 48
# TOTP_VAULT_KEY
openssl rand -base64 32

Then,

docker-compose up -d

Configure Nginx Proxy Manager

Main setup is NPM Docker

Open the NPM UI and add a new proxy host

Domain Names: visits.sagar.se
Scheme: http
Forward Hostname/IP: plausible
Forward Port: 8000

Block common exploits: Yes

Tab SSL/
SSL Certificate: visits.sagar.se
Force SSL yes
HTTP/2 Support yes

Edit npm/docker-compose.yaml and add plausible_plausible-npm​ to the networks like so

1    networks:
2      - plausible_plausible-npm
3networks:
4    plausible_plausible-npm:
5      external: true

Would likely need to do a docker-compose down before editing the npm/docker-compose.yaml file above, followed by docker-compose up -d after the editing is done.

NOTE: Plausible will need to be started before NPM is started, else NPM will not find the external plausible_plausible-npm network

Set up Google Console Search integration as described at https://plausible.io/docs/self-hosting-configuration#task-one-create-an-oauth-client

Add a page to toggle exclusion from being counted for a particular web browser by downloading the HTML file referenced here and copying it to static/scripts/ so that browsing to https://sagar.se/scripts/toggle-plausible.html will enable toggling of the exclusion.

Reference