How to install Fathom Analytics on Ubuntu 24.04

This article details the installation of Fathom Analytics on Ubuntu 24.04, offering steps to set up PostgreSQL, configure the database, install Fathom, and run it as a system service. By following this guide, users can gain valuable website insights while prioritizing visitor privacy and optimizing web traffic.

This article explains how to install Fathom Analytics on Ubuntu 24.04.

With Fathom Analytics installed on Ubuntu, you can track your website traffic and gain valuable insights into visitor behavior. This privacy-focused analytics tool is designed to help website owners understand their audience without compromising data privacy.

By harnessing the power of Fathom Analytics on Ubuntu, you can feel empowered with the knowledge of your website’s performance, all while respecting the privacy of your visitors.

The steps below walk you through installing Fathom Analytics on Ubuntu 24.04.

Install PostgreSQL

Before installing Fathom, you must install a database server to store its content. A database server that works excellently with Fathom is PostgreSQL.

Use the steps below to install it on Ubuntu.

First, add the PostgreSQL GPG key to Ubuntu. Run the command below to do that.

sudo apt install curl
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql-key.gpg >/dev/null

Then, add the PostgreSQL APT repository to your sources list.

sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgresql-key.gpg arch=amd64] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Next, update and refresh the repository list and install PostgreSQL.

sudo apt update
sudo apt install postgresql postgresql-contrib

More details on installing PostgreSQL can be found in the link below.

How to install PostgreSQL on Ubuntu

Configure PostgreSQL and create a Fathom database

Once PostgreSQL is installed, use the steps below to configure it and create a database for  Fathom.

First, log on to the PostgreSQL console by running the command below.

sudo -u postgres psql

Run the command below to change or create a password for the administrator account. Confirm the password when prompted.

\password postgres

Next, create a  Fathom database user account called ‘fathomuser.’

CREATE ROLE fathomuser WITH LOGIN ENCRYPTED PASSWORD 'type_strong_password_here';

Replace ‘type_strong_password_here‘ with your password.

Next, create a ‘fathomdb‘ database for Fathom and make the user above owner.

CREATE DATABASE fathomdb OWNER fathomuser;

Exit the database console.

\q

Install Fathom

Now that PostgreSQL is installed and configured continue to download and set up Fathom analytics below.

First, create a user account for Fathom Analytics.

sudo adduser --home /opt/fathom --disabled-password fathom

Next, make the fathom user owner of the /opt/fathom directory.

sudo chown -R fathom:fathom /opt/fathom

Next, download the Fathom binary package using the wget command below.

Once downloaded, extract the fathom binary file to the /usr/local/bin directory and make the fathom binary file executable.

wget https://github.com/usefathom/fathom/releases/download/v1.3.1/fathom_1.3.1_linux_amd64.tar.gz
sudo tar -C /usr/local/bin -xzf fathom_1.3.1_linux_amd64.tar.gz
sudo chmod +x /usr/local/bin/fathom

Next, switch to the Fathom user account and navigate to the Fathom’s directory by running the command below.

sudo su - fathom
cd /opt/fathom

Then, create a new data directory and .env file using the command below.

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

Use the following nano editor command to open the .env file.

nano /opt/fathom/data/.env

Add the lines below to the file, changing the details of the PostgreSQL database created above.

For FATHOM_SECRET, generate 20 alphanumeric characters and use it in the file.

FATHOM_GZIP=true
FATHOM_DEBUG=true
FATHOM_DATABASE_DRIVER="postgres"
FATHOM_DATABASE_NAME="fathomdb"
FATHOM_DATABASE_USER="fathomuser"
FATHOM_DATABASE_PASSWORD="type_password_here"
FATHOM_DATABASE_HOST="127.0.0.1"
FATHOM_DATABASE_SSLMODE="disable"
FATHOM_SECRET="fetL5tQSeKzK7eToKfD2"

Save and exit the file when finished.

While still in the Fathom home directory, change to the data folder and run the command below to start the Fathom server.

cd /opt/fathom/data
fathom server

Once started, browse to the server hostname or IP address followed by port 8080.

http://localhost:8080

You should see the Fathom dashboard with a JavaScript code you can copy to the host you want to monitor.

Run Fathom as a System Service

You can set it up as a system service to make Fathom easier to manage. Then, use the systemctl command to manage it.

Run the command below to create a Fathom system service file.

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

Copy and paste the lines below in the file and save it.

[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

Enable and start Fathom.

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

The status option will display Fathom as running and healthy.

fathom.service - Starts the fathom server
Loaded: loaded (/etc/systemd/system/fathom.service; enabled; preset: enabl>
Active: active (running) since Mon 2024-06-24 16:55:01 CDT; 6s ago
Main PID: 10703 (fathom)
Tasks: 6 (limit: 4561)
Memory: 6.3M (peak: 6.7M)
CPU: 29ms
CGroup: /system.slice/fathom.service
└─10703 /usr/local/bin/fathom server

Every time you start the machine, Fathom should be accessible using the local server name or IP address followed by the port number.

Set up a reverse proxy

Now that Fathom is set up, you can use a reverse proxy to ensure Fathom access via a domain name and optimize for web traffic.

The two links below show you how to set up a reverse proxy using Nginx or Apache.

That should do it!

Conclusion:

  • Installing and configuring Fathom Analytics on Ubuntu 24.04 enables tracking website traffic and understanding visitor behavior while prioritizing data privacy.
  • By following the steps outlined in this guide, users can empower themselves with valuable insights into their website’s performance without compromising the privacy of their visitors.
  • Additionally, setting up Fathom as a system service ensures it is easily manageable, and utilizing a reverse proxy optimizes web traffic and allows access via a domain name.
Richard Avatar

Comments

Leave a Reply

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