Installing Plausible Analytics on FreeBSD

This tutorial will guide you through the process of installing Plausible Analytics on the latest version of FreeBSD. Plausible Analytics is an open-source, lightweight, privacy-friendly alternative to Google Analytics that doesn't use cookies, doesn't collect personal data and is fully compliant with GDPR, CCPA and PECR regulations.

Prerequisites

To complete this tutorial, you will need:

Step 1: Install Docker

Plausible Analytics is packaged as a Docker container, so you'll need Docker installed on your FreeBSD instance. If you don't already have Docker installed, you can install it by running the following command:

pkg install docker

Step 2: Create a persistent data directory

To persist data between container restarts and updates, we'll create a data directory for Plausible Analytics. Run the following command to create the directory:

mkdir -p /opt/plausible-analytics/data

Step 3: Create a Docker network

We'll create a Docker network that the Plausible Analytics container will use. Run the following command to create the network:

docker network create plausible-analytics

Step 4: Run the Plausible Analytics container

Now we're ready to run the Plausible Analytics container. Run the following command, replacing example.com with your domain name and PLAUSIBLE_DATA=/opt/plausible-analytics/data with the path to your data directory:

docker run -d \
  --name plausible-analytics \
  --restart=always \
  --network=plausible-analytics \
  --env "PLAUSIBLE_HOST=https://example.com" \
  --env "PLAUSIBLE_DATA=/opt/plausible-analytics/data" \
  -v /opt/plausible-analytics/data:/plausible/data \
  plausible/analytics:latest

This command will pull the latest version of the Plausible Analytics container and start it in the background with the following options:

Step 5: Configure your web server

Finally, you need to configure your web server to proxy requests to the Plausible Analytics container. If you're using NGINX, you can add the following configuration to your site configuration file, replacing example.com with your domain name:

location = /api/event {
    proxy_pass         http://plausible-analytics:8000;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

location = /api/ping {
    proxy_pass         http://plausible-analytics:8000;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

location / {
    proxy_pass         http://plausible-analytics:8080;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

This configuration will proxy requests to the Plausible Analytics container on ports 8000 and 8080.

Conclusion

Congratulations! You've successfully installed Plausible Analytics on the latest version of FreeBSD. You can now access your analytics dashboard by visiting your domain name in a web browser. If you encounter any issues, refer to the Plausible Analytics documentation or contact their support team.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!