Self host Plausible with Fly
Plausible.io đź’ś Fly.io
Upgraded to version 2.0 following instructions here 2023-08-15
The latent docker image issue was gone, simply using the latest release tag plausible@latest in Dockerfile would workCity level data is automatically downloaded. Set an env variable MAXMIND_LICENSE_KEY before app startup if you need itRan into some Clickhouse connection issue during app boot up, resolved by setting CLICKHOUSE_DATABASE_URL (plausible_events_db) and DATABASE_URL (plausible_db) with their ip v4 addresses
Plausible.io is an open source alternative to Google Analytics created by some inspiring indie devs. Its vision to be transparent about how website traffic data is handled really separates it apart from other proprietary alternatives. I first came across it from above Indie Hacker Podcast and managed to get it hosted on an EC2 container. However, the AWS bills increased too fast that I had to switch to Fly.io for cheaper hosting.
How
By following the rule of “Don’t reinvent the wheel”, I found that similar need was already addressed by others, well summarized in a blog post plus a code repository.
- Blog https://intever.co/blog/plausible-self-hosted-with-fly
- GitHub https://github.com/intever/plausible-hosting
I basically went through the same process by following the instructions, besides fixing some issues related to outdated information. In addition, I also enabled the https://github.com/plausible/analytics/pull/1449 available in recent release.
Problems
details
#### Plausible deployment failures
- Caused by under provisioning
Solution:
fly scale memory 1024- release_command in fly.toml failed to create and migrate DB
> I wound up deploying once to create the DB, then again to migrate the DB when the first deploy failed to run.
Solution:
1. Update fly.toml
- release_command = 'db migrate'
+ release_command = 'db createdb'2. Deploy
3. Run the migration command
fly ssh console
entrypoint.sh db migratedetails
#### The latest docker image release are behind development (i.e. master branch)
- DB connection issue. Fly.io does all internal networking over IPv6, and that required a Change to how phoenix apps are built. The phx generators have been updated, but it required a PR for plausible.
- The other issue is that I wanted to force_ssl , but that’s a compile-time configuration
config :plausible, PlausibleWeb.Endpoint,
force_ssl: [rewrite_on: [:x_forwarded_proto]],- Missing features like region/city level information
Solution:
1. Fork https://github.com/plausible/analytics
2. Copy fly.toml from the plausible directory to the forked analytics directory
3. Deploy change fly deploy
Guides
Prerequisite
Embedded: bookmark
Make sure fly CLI is installed and is logged in to be able to run other commands
brew install fly
fly auth loginPostgres DB
fly pg create plausible-db
Clickhouse
cd clickhousefly apps create plausible_clickhousefly vol create plausible_clickhouse_datafly deploy
Plausible (Analytics)
cd plausiblefly apps create plausiblefly pg attach plausible-db- Set secrets
openssl rand -base64 64 | tr -d '\n' ; echo
fly secrets set SECRET_KEY_BASE=`FROM ABOVE` \
ADMIN_USER_NAME=`username` \
ADMIN_USER_EMAIL=`email` \
ADMIN_USER_PWD=`password` \
BASE_URL=`host_url`fly scale memory 1024scale up to avoid under provision
Add Cities Level Data
Based on https://github.com/plausible/analytics/discussions/2324
cd plausible- Create a volume for geo data
fly vol create myapp_data
# fly.toml
[mounts]
source="myapp_data"
destination="/data"- Download
geonames.csv&geolite2-city.mmdbto the container
1. fly ssh console
2. cd /data
# geonames.csv
wget https://s3.eu-central-1.wasabisys.com/plausible-application/geonames.csv
# geolite2-city.mmdb
export MAXMIND_LICENSE_KEY=LNpsJCCKPis6XvBP # replace this with your own
wget "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${MAXMIND_LICENSE_KEY}&suffix=tar.gz" -O geolite2-city.mmdb.gz
gunzip geolite2-city.mmdb.gz- Set Secrets to the data location
fly secrets set IP_GEOLOCATION_DB='/data/geolite2-city.mmdb' GEONAMES_SOURCE_FILE='/data/geonames.csv'DNS Entries / SSL
fly certs create `BASE_URL`Note:details
#### Self host on EC2 guide
1. Bootstrap an EC2 Ubuntu instance (e.g. t2.medium, \> 2G RAM) w/ security group inbound rules configured
- HTTP 80
- HTTPS 443
2. Install Nginx https://ubuntu.com/tutorials/install-and-configure-nginx
3. Install Docker & Docker Compose for Ubuntu
1. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04
2. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-20-04
4. Installing Certbot according to the EFF https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal
5. Continue with https://plausible.io/docs/self-hosting#up-and-running
Comments