Install Fathom Analytics on Ubuntu 22.04

In this guide, we want to teach you to Install and Secure Fathom Analytics on Ubuntu 22.04.

Fathom Analytics is a simple, open-source web analytics platform that helps you track, analyze, and report your website data while placing a premium on data privacy. So, unlike Google Analytics, Fathom does not collect the personal data of your website visitors. 

‍And it does not use cookies, so you won’t have to bother about the ugly cookies notification bar on your website anymore.

‍Fathom is an easy-to-use analytics tool for website owners at any technical level. It has a dashboard that allows you to monitor:

  • number of website visitors
  • site pageviews
  • bounce rate
  • average time on site 
  • goals completion

Steps To Install and Secure Fathom Analytics on Ubuntu 22.04

To complete this guide, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.

Also, you need a domain name that is pointed to your server’s IP address.

Install Fathom on Ubuntu 22.04

First, update your local package index with the following command:

sudo apt update

download Fathom Analytics

Then, you need to download the latest version of Fathom from Github. Visit the GitHub page for Fathom releases.

Find the Fathom latest release for Linux-amd64-tar.gz. Copy the link address of it and use the curl command to download it:

sudo curl -L -O https://github.com/usefathom/fathom/releases/download/v1.3.0/fathom_1.3.0_linux_amd64.tar.gz

When your download is completed, extract your Fathom downloaded file to the /usr/local/bin directory on Ubuntu 22.04 with the command below:

sudo tar -C /usr/local/bin/ -xzf fathom*.tar.gz fathom

Now you need to make your file executable with the following command:

sudo chmod +x /usr/local/bin/fathom

Verify that your Fathom binary is installed on your server by checking its version:

fathom --version

in your output you will see:

Output
Fathom version 1.3.0, commit ae8d578fcab8e971e0982cd969a94e3ecfb937b0, built at 2022-11-26T17:15:42Z

Configure Fathom on Ubuntu 22.04

To run the Fathom server, you need to create a Fathom user on Ubuntu 22.04. To do this, run the following command:

sudo adduser --system --group --home /opt/fathom fathom

Now switch to the Fathom user’s home directory:

cd /opt/fathom

Here you need to execute some commands that need to be run as a Fathom user.

Open a bash shell with the Fathom user:

sudo -u fathom bash

Generate Fathom Secret string

You need to generate a secret string that Fathom will use for signing and encryption purposes with the command below:

openssl rand --base64 32

Your output will similar to this:

Output
Yps7ZdwDMnQUwKEf/35QMff9BVD2QdcjfJbzMzGkzbE=

Create a New Env File

Next, you need to create a new env file for the configuration file with your favorite text editor, here we use vi:

vi /opt/fathom/.env

Then, add the following contents to the file and replace the Fathom secret with the string that you have generated before:

FATHOM_SERVER_ADDR="127.0.0.1:8080"
FATHOM_DATABASE_DRIVER="sqlite3"
FATHOM_DATABASE_NAME="fathom.db"
FATHOM_SECRET="your-secret-string"

When you are done, save and close the file.

Add User To Fathom Instance

Now that your database is configured, you can add the first user to your Fathom instance:

fathom user add --email="your_email" --password="your_password"

In your output you will see:

Output
INFO[0000] Fathom version 1.3.0, commit ae8d578fcab8e971e0982cd969a94e3ecfb937b0, built at 2022-11-26T17:15:42Z
INFO[0000] Configuration file: /opt/fathom/.env
INFO[0000] Connected to sqlite3 database: /opt/fathom/fathom.db
[DEPRECATED] packr.NewBox has been deprecated.
        Use packr.New instead.
INFO[0000] Applied 27 database migrations!
INFO[0000] Created user [email protected]

Start Fathom Server on Ubuntu 22.04

At this point, you can start your Fathom server on Ubuntu 22.04 with the following command:

fathom server

Your output will similar to this:

Output
INFO[0000] Fathom version 1.3.0, commit ae8d578fcab8e971e0982cd969a94e3ecfb937b0, built at 2022-11-26T17:15:42Z
INFO[0000] Configuration file: /opt/fathom/.env
INFO[0000] Connected to sqlite3 database: /opt/fathom/fathom.db

Then, open another terminal that is connected to your server, and from the Fanthom instance run the following command:

curl localhost:8080

You will see a few lines of HTML code, which means that the server is up and responding to requests on localhost.

Output
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
  <title>Fathom - simple website analytics</title>
  <link href="assets/css/styles.css?t=1669482962932" rel="stylesheet">
  <meta charset="utf-8">
...

Exit from the Fathom server by pressing the CTRL + C, and exit from the Fathom user shell with the command below:

exit

Set up a Systemd Unit File for Fathom

The file that you will create, will contain all the configuration details that Systemd needs to properly run the server.

You can create the file with your favorite text editor, here we use vi:

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

Add the following lines to the file:

[Unit]
Description=Fathom Analytics server
Requires=network.target
After=network.target

[Service]
Type=simple
User=fathom
Group=fathom
Restart=always
RestartSec=3
WorkingDirectory=/opt/fathom
ExecStart=/usr/local/bin/fathom server

[Install]
WantedBy=multi-user.target

When you are done, save and close the file.

Next, reload the systemd config to apply the changes:

sudo systemctl daemon-reload

Enable the Fathom service to start on boot on Ubuntu 22.04:

sudo systemctl enable fathom.service

Now start your service with the following command:

sudo systemctl start fathom

Check that the Fathom service is active and running on your Ubuntu 22.04:

sudo systemctl status fathom

In your output you will see:

Output
● fathom.service - Fathom Analytics server
     Loaded: loaded (/etc/systemd/system/fathom.service; enabled; vendor prese>
     Active: active (running) since Sat 2023-01-28 12:18:43 UTC; 14s ago
   Main PID: 3263 (fathom)
      Tasks: 5 (limit: 4575)
     Memory: 6.6M
        CPU: 67ms
     CGroup: /system.slice/fathom.service
             └─3263 /usr/local/bin/fathom server
...

Configure Nginx as a reverse proxy for Fathom

At this point, you need to configure Nginx as a reverse proxy for the Fathom service on Ubuntu 22.04.

First, install Nginx with the following command:

sudo apt install nginx

Then, you need to allow traffic for Nginx through the UFW firewall with the command below:

sudo ufw allow "Nginx Full"

Next, you need to create a new Nginx configuration file for the Fathom on Ubuntu 22.04:

sudo vi /etc/nginx/sites-available/fathom.conf

Add the following contents to the file and replace the server name with your domain name:

server {
    listen 80;
    server_name your-domain-name;

    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; 
    }
}

When you are done, save and close the file.

Then, enable the configuration file with the command below:

sudo ln -s /etc/nginx/sites-available/fathom.conf /etc/nginx/sites-enabled/

Verify that the configuration file syntax is ok with the following command:

sudo nginx -t

In your output you will see:

Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx to apply the changes:

sudo systemctl reload nginx

Access Fathom Web Interface

At this point, you can access the Fathom web interface by typing your domain name in your web browser:

http://your_domain_here

You will see:

Fathom Login
Fathom Login

Secure Fathom on Ubuntu 22.04

It is recommended to secure your Fathom service. To do this, follow the steps below:

First, you need to install Certbot and its Nginx plugin with the command below:

sudo apt install certbot python3-certbot-nginx

Then, run the Certbot with your domain:

sudo certbot --nginx -d your_domain_here

You will be asked to enter your Email address and agree with the terms of services.

Next, you’ll be asked if you want to redirect all HTTP traffic to HTTPS. It’s up to you, but this is generally recommended and safe to do.

In your output you will see:

Output
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/your-domain/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/your-domain/privkey.pem
This certificate expires on 2023-04-28.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for your-domain to /etc/nginx/sites-enabled/fathom.conf
Congratulations! You have successfully enabled HTTPS on https://your-domain

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Now you can access the Fathom web interface again by https and you will see the lock icon in your browser bar.

Enter the email address and password that you have created for the Fathom and you will see:

Fathom dashboard
Fathom dashboard

At this point, you have successfully installed and secured your Fathom analytics software.

Conclusion

At this point, you have learned to Install, Configure, and Secure Fathom Analytics on Ubuntu 22.04.

Hope you enjoy using it.

You may be like these articles on the Orcacore website:

Install Memcached on Ubuntu 22.04

Install MySQL Workbench on Ubuntu 22.04

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular