Installing Fathom: A Step-by-Step Guide to Privacy-Focused Web Analytics on Ubuntu

Fathom is a privacy-centric web analytics tool offering GDPR compliance, eliminating the need for cookie banners. Unlike Google Analytics, it respects user privacy without compromising visitor data.

This guide walks you through the installation of Fathom on an Ubuntu 22.04 server, using PostgreSQL and Nginx as a reverse proxy.

Prerequisites

Before installing Fathom, ensure you have:

  • An Ubuntu 22.04 server.
  • A non-root user with sudo privileges.
  • A domain name pointed to your server’s IP address.

Installing PostgreSQL Server

Fathom requires PostgreSQL for its database. Begin by updating your Ubuntu package repository:

sudo apt update

update repo

Install the PostgreSQL server with this command:

sudo apt install postgresql

Confirm by entering Y.

install postgresql

Verify that PostgreSQL is enabled and running with:

sudo systemctl is-enabled postgresql
sudo systemctl status postgresql

check postgresql

Creating PostgreSQL Database and User

Next, create a database and user for Fathom.

Login as the postgres user:

sudo -u postgres psql

Execute the following queries to create a new database and user:

CREATE USER fathom WITH CREATEDB CREATEROLE PASSWORD 'password';
CREATE DATABASE fathomdb OWNER fathom;

create database user

Verify database and user creation with:

\du
\l

Exit PostgreSQL with q or Ctrl+d.

check database user

Connect to the database:

sudo -u postgres psql -U fathom -h 127.0.0.1 -d fathomdb
\conninfo

check user auth

Installing Fathom on Ubuntu

With PostgreSQL set up, proceed with Fathom installation:

  • Setting Up User and Downloading Fathom
  • Configuring Fathom
  • Running Fathom as a Systemd Service

Setting up User and Downloading Fathom

Create a system user for Fathom:

sudo useradd -r -d /opt/fathom fathom

Set up the home directory:

sudo mkdir -p /opt/fathom
sudo chown -R fathom:fathom /opt/fathom

Download the Fathom binary:

wget https://github.com/usefathom/fathom/releases/download/v1.3.1/fathom_1.3.1_linux_amd64.tar.gz

create user

Extract and make the binary executable:

tar -C /usr/local/bin -xzf fathom_1.3.1_linux_amd64.tar.gz
chmod +x /usr/local/bin/fathom

Verify installation:

which fathom
fathom --version

check fathom version

Configuring Fathom

Generate a random password secret:

head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20 ; echo ''

Navigate to the /opt/fathom directory:

cd /opt/fathom

Create required directories and files:

sudo -u fathom mkdir -p /opt/fathom/data
sudo -u fathom touch /opt/fathom/data/.env

Open the .env file:

sudo -u fathom nano /opt/fathom/data/.env

Insert configuration, substituting your own values:

FATHOM_GZIP=true
FATHOM_DEBUG=true
FATHOM_DATABASE_DRIVER="postgres"
FATHOM_DATABASE_NAME="fathomdb"
FATHOM_DATABASE_USER="fathom"
FATHOM_DATABASE_PASSWORD="password"
FATHOM_DATABASE_HOST="127.0.0.1"
FATHOM_DATABASE_SSLMODE="disable"
FATHOM_SECRET="qDQ4fawzKOfBAtJ3O4ID"

Save and exit the file.

configure fathom

Run Fathom:

cd /opt/fathom/data
sudo -u fathom fathom server

test fathom

Running Fathom as Systemd Service

Create a new systemd service file:

sudo nano /etc/systemd/system/fathom.service

Input the following configuration:

[Unit]
Description=Starts the fathom server
Requires=network.target
After=network.target
[Service]
Type=simple
User=fathom
Restart=always
RestartSec=3
WorkingDirectory=/opt/fathom/data
ExecStart=/usr/local/bin/fathom server

[Install]
WantedBy=multi-user.target

Save and close.

Reload systemd and start the service:

sudo systemctl daemon-reload
sudo systemctl start fathom
sudo systemctl enable fathom

Verify service status:

sudo systemctl status fathom

fathom port

Creating Fathom User

Navigate to the Fathom data directory:

cd /opt/fathom/data

Create a Fathom user:

sudo -u fathom fathom user add --email="bob@howtoforge.local" --password="password"

create user

Installing and Configuring Nginx as Reverse Proxy

Install Nginx:

sudo apt install nginx -y

install nginx

Create a server block for Fathom:

sudo nano /etc/nginx/sites-available/fathom
server {
 listen 80;
 server_name fathom.howtoforge.local;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
}

Activate the configuration and test Nginx:

sudo ln -s /etc/nginx/sites-available/fathom /etc/nginx/sites-enabled/
sudo nginx -t

Restart Nginx:

sudo systemctl restart nginx

nginx reverse proxy

Securing Fathom with UFW

Configure UFW to allow necessary traffic:

sudo ufw allow OpenSSH
sudo ufw enable

enable ufw

Allow Nginx traffic:

sudo ufw allow 'Nginx Full'

Verify UFW settings:

sudo ufw status

add verify ufw

Enable HTTPS via Certbot

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

install certbot

Generate SSL certificates:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email bob@howtoforge.local -d fathom.howtoforge.local

Accessing Fathom Installation

Visit https://fathom.howtoforge.local/ to access Fathom. Log in with your credentials.

login fathom

Create your first tracker and copy the tracking code to your target site:

create site

tracking code

Conclusion

Congratulations! Fathom is now installed on your Ubuntu server, complete with PostgreSQL and Nginx as a reverse proxy. You’ve secured Fathom with HTTPS using Let’s Encrypt and configured UFW for network security.

Frequently Asked Questions (FAQ)

1. What is Fathom?

Fathom is a privacy-focused web analytics tool that complies with GDPR and does not require cookie banners.

2. Can I use any PostgreSQL version?

Fathom should work well with most recent PostgreSQL versions, but it’s always best to check the official documentation for any specific version requirements.

3. Why do I need Nginx?

Nginx is used as a reverse proxy to handle incoming web requests and pass them to the Fathom server running on port 8080. It also helps in securing your server with SSL via Let’s Encrypt.

4. How do I update Fathom?

Updating Fathom typically involves downloading the latest binary release from GitHub, replacing the existing binary, and restarting the Fathom service. Always refer to the official releases page for the latest updates and instructions.

5. What should I do if I face issues?

First, check the logs by executing sudo journalctl -u fathom for systemd logs and sudo tail -f /var/log/nginx/error.log for Nginx logs. For further assistance, consider the community forums or GitHub issues page.