Setting Up Plausible Analytics

Plausible Analytics is a lightweight, open-source web analytics tool. It is designed to be simple to use, privacy-friendly, and provides essential website statistics without the use of cookies or tracking personal data. This guide will walk you through the steps to self-host Plausible Analytics using Docker and configure it with either NGINX or Apache2 as a reverse proxy.

Prerequisites

  • A server running a Debian-based distribution (like Ubuntu)
  • Docker and Docker Compose installed
  • Domain name and SSL certificate (self-signed or from a certificate authority)
  • Basic knowledge of command-line operations

Step 1: Clone the Plausible Hosting Repository

git clone https://github.com/plausible/hosting
cd hosting
curl -L https://github.com/plausible/hosting/archive/master.tar.gz | tar -xz
cd hosting-master

Step 2: Generate a Secret Key

Generate a 64-character secret key:

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

Step 3: Configure Plausible

Create and edit the plausible-conf.env file:

nano plausible-conf.env

Insert the following configuration, replacing placeholder values with your actual data:

BASE_URL=https://domain.com
SECRET_KEY_BASE=<GeneratedRandomString>
DISABLE_REGISTRATION=invite_only
MAILER_EMAIL=noreply@domain.com
SMTP_HOST_ADDR=smtp.example.com
SMTP_HOST_PORT=587
SMTP_USER_NAME=noreply@domain.com
SMTP_USER_PWD=<password>
SMTP_HOST_SSL_ENABLED=false
SMTP_RETRIES=2

Step 4: Configure Docker Compose

Edit the docker-compose.yml file to bind Plausible to the localhost interface:

nano docker-compose.yml

Make sure the ports section looks like this:

    ports:
      - 127.0.0.1:8000:8000

Step 5: Launch Plausible

Start Plausible using Docker Compose:

sudo docker-compose up -d

Step 6: Configure the Web Server

Option 1: Using NGINX

Create an NGINX configuration file:

nano /etc/nginx/sites-available/plausible

Insert the following configuration, replacing placeholders with your actual domain and certificate paths:

server {
    listen              443 ssl;
    server_name         domain.com;
    ssl_certificate     /etc/nginx/ssl/chain.crt;
    ssl_certificate_key /etc/nginx/ssl/rootCA.key;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Protocol $scheme;
    }
}

Enable the NGINX site and restart the service:

ln -s /etc/nginx/sites-available/plausible /etc/nginx/sites-enabled/plausible
systemctl restart nginx

Option 2: Using Apache2

Create an Apache2 configuration file:

nano /etc/apache2/sites-available/plausible.conf

Insert the following configuration, replacing placeholders with your actual domain and certificate paths:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName domain.com
ServerAdmin user@domain.com

ErrorLog ${APACHE_LOG_DIR}/domain.error.log
CustomLog ${APACHE_LOG_DIR}/domain.access.log combined

ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
ProxyRequests Off

SSLEngine on
SSLVerifyClient none
SSLCertificateFile "/etc/apache2/ssl/domain.crt"
SSLCertificateChainFile "/etc/apache2/ssl/domain.ca-bundle"
SSLCertificateKeyFile "/etc/apache2/ssl/rootCA.key"
</VirtualHost>
</IfModule>

Enable the Apache2 site and restart the service:

a2ensite plausible
systemctl reload apache2
systemctl restart apache2

Updating Plausible

To update Plausible to the latest version, follow these steps:

sudo docker-compose down --remove-orphans
sudo docker-compose pull plausible
sudo docker-compose up -d

Restart your web server:

sudo systemctl restart nginx  # For NGINX

or

sudo systemctl restart apache2  # For Apache2

Summary

You have now successfully installed and configured Plausible Analytics on your server. Whether using NGINX or Apache2, your setup should be live and ready to collect web analytics data. Remember to secure your server and maintain regular updates to keep your software and configurations secure.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top