Share your love
Install and Secure Fathom Analytics on Ubuntu 20.04
In this article, we want to teach you How To Install and Secure Fathom Analytics on Ubuntu 20.04.
Fathom Analytics is an open-source tool in the General Analytics category of a tech stack.
Fathom tracks users on a website (without collecting personal data) and gives you a non-nerdy breakdown of your top content and top referrers. It does so with user-centric rights and privacy, and without selling, sharing, or giving away the data you collect.
It’s simple and easy to use for website owners at any technical level.
How To Install and Secure Fathom Analytics on Ubuntu 20.04
Before you start to install Fathom Analytics on your server, you need to 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 article the Initial Server Setup with Ubuntu 20.04.
Also, you need a domain name that pointed to your server’s IP address.
Now follow the steps below to set up Fathom Analytics on Ubuntu 20.04.
Install Fathom on Ubuntu 20.04
First, update your local package index with the following command:
sudo apt update
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:
curl -L -O https://github.com/usefathom/fathom/releases/download/v1.2.1/fathom_1.2.1_linux_amd64.tar.gz
When your download is completed, extract your Fathom downloaded file to the /usr/local/bin directory on Ubuntu 20.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.2.1, commit 8f7c6d2e45ebb28651208e2a7320e29948ecdb2c, built at 2018-11-30T09:21:37Z
Configure Fathom on Ubuntu 20.04
To run the Fathom server, you need to create a Fathom user on Ubuntu 20.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
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 be similar to this:
Output
vDnTQba59iTGphW3MgQg49vYkTBNbCaWBUdwjtmFc2c=
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_random_string_here"
When you are done, save and close the file.
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.2.1, commit 8f7c6d2e45ebb28651208e2a7320e29948ecdb2c, built at 2018-11-30T09:21:37Z
INFO[0000] Configuration file: /opt/fathom/.env
INFO[0000] Connected to sqlite3 database: /opt/fathom/fathom.db
INFO[0000] Applied 26 database migrations!
INFO[0000] Created user olivia@orcacore.com
At this point, you can start your Fathom server on Ubuntu 20.04 with the following command:
fathom server
Your output will be similar to this:
Output
INFO[0000] Fathom version 1.2.1, commit 8f7c6d2e45ebb28651208e2a7320e29948ecdb2c, built at 2018-11-30T09:21:37Z
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=1543569696966" rel="stylesheet">
<meta charset="utf-8">
<meta name="referrer" content="no-referrer">
...
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 20.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 20.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 preset> Active: active (running) since Wed 2022-01-05 11:47:24 CET; 1min 3s ago Main PID: 6735 (fathom) Tasks: 7 (limit: 2282) Memory: 9.9M CGroup: /system.slice/fathom.service └─6735 /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 20.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 20.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;
listen [::]:80;
server_name your_domain_here;
access_log /var/log/nginx/fathom.access.log;
error_log /var/log/nginx/fathom.error.log;
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
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
Now you can access the Fathom web interface by typing your domain name in your web browser:
http://your_domain_here
You will see:
Now that you have your site up and running over HTTP, it’s time to secure the connection with Certbot and Let’s Encrypt certificates.
Secure Fathom on Ubuntu 20.04
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:
Congratulations! You have successfully enabled https://your-domain You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=your-domain - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/your-domain/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/your-domain/privkey.pem Your cert will expire on 2022-04-05. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - 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:
At this point, you have successfully installed and secured your Fathom analytics software.
Conclusion
Here you learn to install and secure Fathom on Ubuntu 20.04.
Hope you enjoy using it.
Also, you might find these links interesting: