plausible / community-edition

Example Docker Compose setup for hosting Plausible Community Edition
1.45k stars 304 forks source link

Document setting up plausible-ce in local machine for locally running single page app url #157

Closed vanuverma closed 2 months ago

vanuverma commented 2 months ago

Hi, Can you please provide a step-by-step guide on how to setup plausible-ce in local machine (using Docker) and make it track page visits for a locally running single-page application? I am trying to verify whether plausible is suitable for my use case, and wanted to try it out locally first as I don't have any domain as of now. Also, I may not buy any domain and may run it over intranet. As per the current document, it does not explain what should be the BASE_URL and how to configure that to track a locally running SPA (i.e I am running a react-vite app on localhost:5173). A step-by-step guide for this type of scenarios would be very helpful to test plausible-ce locally prior to making any decision. Thanks.

vanuverma commented 2 months ago

In addition to the above, it would be nice if you can provide commands for multiple OS (i.e. for mac, windows, linux etc. separately). Thanks

vanuverma commented 2 months ago

When I tried to use a public domain url (hosted via aws amplify), I am able to see the user registration page for plausible-ce locally (http://localhost:80/register), but the register button click does not do anything. Below is my docker container log: ` 2024-09-26 12:13:38 Loading plausible.. 2024-09-26 12:13:38 Starting dependencies.. 2024-09-26 12:13:38 Starting repos.. 2024-09-26 12:13:38 02:13:38.967 [error] Postgrex.Protocol (#PID<0.150.0>) failed to connect: (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "plausible_db" does not exist 2024-09-26 12:13:38 02:13:38.967 [error] Postgrex.Protocol (#PID<0.149.0>) failed to connect: (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "plausible_db" does not exist 2024-09-26 12:13:38 02:13:38.981 [error] Ch.Connection (#PID<0.158.0>) failed to connect: (Ch.Error) Code: 81. DB::Exception: Database plausible_events_db does not exist. (UNKNOWN_DATABASE) (version 24.3.3.102 (official build)) 2024-09-26 12:13:38 2024-09-26 12:13:38 02:13:38.981 [error] Ch.Connection (#PID<0.157.0>) failed to connect: (Ch.Error) Code: 81. DB::Exception: Database plausible_events_db does not exist. (UNKNOWN_DATABASE) (version 24.3.3.102 (official build)) 2024-09-26 12:13:38 2024-09-26 12:13:39 Creating Plausible.Repo database.. 2024-09-26 12:13:39 Creating Plausible.IngestRepo database.. 2024-09-26 12:13:39 Creation of Db successful! 2024-09-26 12:13:40 Loading plausible.. 2024-09-26 12:13:40 Starting dependencies.. 2024-09-26 12:13:40 Starting repos.. 2024-09-26 12:13:45 list-partitions Done! 2024-09-26 12:13:45 2024-09-26 12:13:45 ------------------------------------------------------------------------------ 2024-09-26 12:13:45 get-sessions-table-settings Done! 2024-09-26 12:13:45 2024-09-26 12:13:45 ------------------------------------------------------------------------------ 2024-09-26 12:13:45 drop-sessions-tmp-table Done! 2024-09-26 12:13:45 2024-09-26 12:13:45 ------------------------------------------------------------------------------ 2024-09-26 12:13:45 create-sessions-tmp-table Done! 2024-09-26 12:13:45 2024-09-26 12:13:45 ------------------------------------------------------------------------------ 2024-09-26 12:13:45 exchange-sessions-tables Done! 2024-09-26 12:13:45 2024-09-26 12:13:45 ------------------------------------------------------------------------------ 2024-09-26 12:13:45 Migration done! 2024-09-26 12:13:45 Backfilling legacy site import across 0 sites (DRY RUN: false)... 2024-09-26 12:13:45 Finished backfilling sites. 2024-09-26 12:13:45 Adjusting end dates of 0 site imports (DRY RUN: false)... 2024-09-26 12:13:45 Finished adjusting end dates of site imports. 2024-09-26 12:13:45 Finished 2024-09-26 12:13:46 truncate-location-data-table Done! 2024-09-26 12:13:46 2024-09-26 12:13:46 ------------------------------------------------------------------------------ 2024-09-26 12:13:46 create-location-data-table Done! 2024-09-26 12:13:46 2024-09-26 12:13:46 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 update-location-data-dictionary Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:47 add-alias-column Done! 2024-09-26 12:13:47 2024-09-26 12:13:47 ------------------------------------------------------------------------------ 2024-09-26 12:13:48 add-alias-column Done! 2024-09-26 12:13:48 2024-09-26 12:13:48 ------------------------------------------------------------------------------ 2024-09-26 12:13:48 update-location-data-table-comment Done! 2024-09-26 12:13:48 2024-09-26 12:13:48 ------------------------------------------------------------------------------ 2024-09-26 12:13:53 02:13:53.854 [notice] Generating a temporary self-signed certificate. This certificate will be used until a proper certificate is issued by the CA server. 2024-09-26 12:14:01 02:14:01.098 [error] Use of --no-self-upgrade is deprecated. 2024-09-26 12:14:01 Saving debug log to /var/lib/plausible/site_encrypt/certbot/acme-v02.api.letsencrypt.org/log/letsencrypt.log 2024-09-26 12:14:01 Account registered. 2024-09-26 12:14:01 Requesting a certificate for dev..amplifyapp.com 2024-09-26 12:14:01 2024-09-26 12:14:01 Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems: 2024-09-26 12:14:01 Domain: dev..amplifyapp.com 2024-09-26 12:14:01 Type: unauthorized 2024-09-26 12:14:01 Detail: 143.204.215.71: Invalid response from https://dev..amplifyapp.com/.well-known/acme-challenge/f8zGP7Nt6uBfb0QFFdjDbGE_q5fg27hjvnd8M3HQy5I/: 404 2024-09-26 12:14:01 2024-09-26 12:14:01 Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet. 2024-09-26 12:14:01 2024-09-26 12:14:01 Some challenges have failed. 2024-09-26 12:14:01 Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/lib/plausible/site_encrypt/certbot/acme-v02.api.letsencrypt.org/log/letsencrypt.log or re-run Certbot with -v for more details. 2024-09-26 12:14:01 2024-09-26 12:14:01 02:14:01.098 [error] Error obtaining certificate for dev..amplifyapp.com

`

ruslandoga commented 2 months ago

👋 @vanuverma

The local setup is the same except you would set BASE_URL to something like http://localhost:8000 and skip HTTPS.

vanuverma commented 2 months ago

Hi @ruslandoga Thanks for your feedback. Can you please clarify what is the purpose of BASE_URL? In the wiki page in your github repo here, it says link generation. Link generation compared to what, my website or where the plausible is hosted (i.e. in docker)? Should it be the link of my website (i.e. my local react app is running on http://localhost:5173)? Also there isn't any guidance on how to disable HTTPS for localhost. Can you please provide the steps as well? Thanks

ruslandoga commented 2 months ago

👋 @vanuverma

All configuration is about Plausible itself. To disable HTTPS you simply skip setting HTTPS_PORT=443.

Here's how you can run Plausible on localhost:

$ git clone -b v2.1.3 --single-branch https://github.com/plausible/community-edition plausible-ce
$ cd plausible-ce
$ touch .env
$ echo "BASE_URL=http://localhost:8000" >> .env
$ echo "SECRET_KEY_BASE=$(openssl rand -base64 48)" >> .env
$ cat > compose.override.yml << EOF
services:
  plausible:
    ports:
      - 8000:8000
EOF 
$ docker compose up -d
vanuverma commented 2 months ago

Thanks @ruslandoga I will try it out and get back to you.