Install docker

Docker install

Install Plausible

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

Set the docker-compose.yml file to contain the following. Note that the volumes are replaced by local folders for db-data and event-data. Also, the plausible-net network is added to each image and 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.

 1version: "3.3"
 2services:
 3  mail:
 4    image: bytemark/smtp
 5    restart: always
 6
 7  plausible_db:
 8    image: postgres:12
 9    restart: always
10    volumes:
11      - ./db-data:/var/lib/postgresql/data
12    environment:
13      - POSTGRES_PASSWORD=postgres
14    networks:
15      - plausible-net
16
17  plausible_events_db:
18    image: yandex/clickhouse-server:21.3.2.5
19    restart: always
20    volumes:
21      - ./event-data:/var/lib/clickhouse
22      - ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
23      - ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
24    ulimits:
25      nofile:
26        soft: 262144
27        hard: 262144
28    networks:
29      - plausible-net
30
31  plausible:
32    image: plausible/analytics:latest
33    restart: always
34    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"
35    depends_on:
36      - plausible_db
37      - plausible_events_db
38      - mail
39#    ports:
40#      - 8000:8000
41    env_file:
42      - plausible-conf.env
43    networks:
44      - plausible-net
45      - plausible-npm
46#volumes:
47#  db-data:
48#    driver: local
49#  event-data:
50#    driver: local
51#  geoip:
52#    driver: local
53
54networks:
55  plausible-net:
56  plausible-npm:

Edit plausible-env.conf and set the values of all env variables in there. Note that the ADMIN_USER_EMAIL= is needed because that is the username for logging in. The ADMIN_USER_NAME= is not the username for logging in. The secret key can be generated by the command

1openssl rand -base64 64 | tr -d '\n' ; echo

Then,

1docker-compose up -d
2docker exec plausible_plausible_db_1 psql -U postgres -d plausible_db -c "UPDATE users SET email_verified = true;"

Configure Nginx Proxy Manager

Main setup is NPM Docker

Open the NPU UI and add a new proxy host

 1Domain Names: analytics.sagar.se
 2Scheme: http
 3Forward Hostname/IP: plausible
 4Forward Port: 8000
 5
 6Block common exploits: Yes
 7
 8Tab SSL/
 9SSL Certificate: analytics.sagar.se
10Force SSL yes
11HTTP/2 Support yes
12
13Tab Custom locations/
14Location: /
15Scheme: http
16Forward Hostname/IP: plausible
17Forward Port: 8000
18In detailed settings (gear icon) add the line
19proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

NOTE: Adding the proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for; may not be needed because NPM by default adds something like that (albeit with $remote_addr instead of $proxy_add_x_forwarded_for) but just to be on the safe side, since this is recommended by the Plausible docs .

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