Install Fathom Analytics on Ubuntu 22.04: Master Web Analytics

Posted on

Install Fathom Analytics on Ubuntu 22.04: Master Web Analytics

In this comprehensive guide, brought to you by Orcacore, we will delve into the process of Install Fathom Analytics on Ubuntu 22.04. Fathom Analytics stands out as a lightweight, open-source web analytics platform designed to provide website owners with valuable insights into their traffic, behavior, and overall performance. What sets Fathom apart is its commitment to data privacy. Unlike conventional analytics tools like Google Analytics, Fathom deliberately avoids collecting personal data from website visitors.

  • Moreover, it operates without the use of cookies, eliminating the need for those often-intrusive cookie notification banners that can detract from the user experience.
  • Fathom presents a user-friendly interface suitable for users of all technical backgrounds. Its intuitive dashboard allows you to effortlessly monitor key metrics, including:

Steps To Install and Secure Fathom Analytics on Ubuntu 22.04

Before embarking on this installation journey, ensure you’re logged into your Ubuntu 22.04 server as a non-root user with sudo privileges. A basic firewall should also be in place. If you haven’t already, refer to our detailed guide on Initial Server Setup with Ubuntu 22.04 for assistance.

Furthermore, you’ll need a domain name pointed to your server’s IP address.

1. Install Fathom Analytics on Ubuntu 22.04

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

sudo apt update

Download Fathom Analytics

Next, acquire the latest Fathom release from GitHub. Head over to the Fathom releases page.

Locate the "Linux-amd64-tar.gz" asset corresponding to the most recent release. Copy its link address and utilize 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

Once the download is complete, extract the contents of the downloaded archive into the /usr/local/bin directory:

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

Grant execute permissions to the Fathom binary:

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

Confirm the successful installation of the Fathom binary by verifying its version:

fathom --version

The output should resemble this:

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

2. Configure Fathom Analytics on Ubuntu 22.04

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

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

Navigate to the Fathom user’s home directory:

cd /opt/fathom

Now, you’ll execute commands as the Fathom user.

Open a bash shell with the Fathom user:

sudo -u fathom bash

Generate Fathom Secret string

Generate a secure secret string that Fathom will use for signing and encryption:

openssl rand --base64 32

The output will be similar to this:

**Output**
Yps7ZdwDMnQUwKEf/35QMff9BVD2QdcjfJbzMzGkzbE=

Create a New Env File

Create a new .env file for storing Fathom configuration settings using your preferred text editor (e.g., vi):

vi /opt/fathom/.env

Add the following content to the file, replacing <your-secret-string> with the secret string you generated earlier:

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

Save and close the file.

Add User To Fathom Instance

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

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

The output should look like 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
[DEPRECATED] packr.NewBox has been deprecated.
        Use packr.New instead.
INFO[0000] Applied 27 database migrations!
INFO[0000] Created user reita@orcacore.com

3. Start Fathom Server on Ubuntu 22.04

Start the Fathom server on Ubuntu 22.04:

fathom server

The output should be 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

Open another terminal connected to your server and, from within the Fathom instance, run the following command:

curl localhost:8080

This will display a snippet of HTML code, confirming that the server is running 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 the Fathom server by pressing CTRL + C, and exit the Fathom user shell with:

exit

4. Set up a Systemd Unit File for Fathom

Create a systemd unit file to manage the Fathom service. This file contains the configuration details needed by systemd to properly run the server.

Create the file using your preferred text editor:

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

Save and close the file.

Reload the systemd configuration to apply the changes:

sudo systemctl daemon-reload

Enable the Fathom service to automatically start on boot:

sudo systemctl enable fathom.service

Start the Fathom service:

sudo systemctl start fathom

Verify that the Fathom service is active and running:

sudo systemctl status fathom

The output should indicate that the service is active and running:

**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
...

5. Configure Nginx as a reverse proxy for Fathom

Configure Nginx as a reverse proxy for the Fathom service.

Install Nginx:

sudo apt install nginx

Allow traffic for Nginx through the UFW firewall:

sudo ufw allow "Nginx Full"

Create a new Nginx configuration file for Fathom:

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

Add the following content to the file, replacing <your-domain-name> with your actual 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;
    }
}

Save and close the file.

Enable the configuration file:

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

Verify the Nginx configuration syntax:

sudo nginx -t

The output should confirm that the configuration file syntax is correct:

**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

6. Access Fathom Web Interface

Access the Fathom web interface by navigating to your domain name in a web browser:

http://<your_domain_here>

You should see the Fathom login page:

Install Fathom Analytics on Ubuntu 22.04. Fathom Login
Fathom Login

7. Secure Fathom Analytics on Ubuntu 22.04

Secure the Fathom service by installing Certbot and obtaining an SSL certificate.

Install Certbot and its Nginx plugin:

sudo apt install certbot python3-certbot-nginx

Run Certbot with your domain:

sudo certbot --nginx -d <your_domain_here>

You will be prompted to enter your email address and agree to the terms of service.

You will then be asked if you want to redirect all HTTP traffic to HTTPS. It’s generally recommended and safe to do so.

The output will resemble this:

Now, access the Fathom web interface via https. You should see a lock icon in your browser’s address bar, indicating a secure connection.

Enter the email address and password you created earlier to access the Fathom dashboard:

Fathom dashboard

You have now successfully installed and secured Fathom Analytics. This completes the Install Fathom Analytics on Ubuntu 22.04 process.

Conclusion

In this guide, you’ve learned how to Install, Configure, and Secure Fathom Analytics on Ubuntu 22.04. Fathom Analytics offers a privacy-focused approach to web analytics, prioritizing user data protection by abstaining from personal data collection and cookie usage, aligning with privacy regulations like GDPR. It is a great option for those looking to Install Fathom Analytics on Ubuntu 22.04 and achieve privacy-conscious analytics.

Hope you enjoy using it. You may also like these articles:

Install Memcached on Ubuntu 22.04

Install MySQL Workbench on Ubuntu 22.04

Fathom Analytics Setup on Ubuntu 20.04

Install Plausible Analytics on Ubuntu 20.04

Install Elasticsearch Debian 12

How to synchronize time in Debian 12?

Debian 11 Installation Guide: ProcessWire CMS Setup

Install Wireshark on Debian 11 Bullseye Linux

Alternative Solutions for Deploying Fathom Analytics

While the above steps provide a detailed guide for manually installing Fathom Analytics, alternative solutions can streamline the process and offer additional benefits. Here are two different approaches:

1. Docker Compose Deployment:

Docker Compose simplifies the deployment of multi-container Docker applications. We can define the Fathom Analytics instance and its dependencies (like a database, although the example uses SQLite which doesn’t need a separate container) in a docker-compose.yml file. This approach offers consistency and portability across different environments.

Here’s a docker-compose.yml example:

version: "3.8"
services:
  fathom:
    image: usefathom/fathom:latest # Or specify a version
    ports:
      - "8080:8080" # Expose Fathom's port
    volumes:
      - fathom_data:/opt/fathom # Persist data across restarts
    environment:
      FATHOM_SERVER_ADDR: "0.0.0.0:8080" # Listen on all interfaces
      FATHOM_DATABASE_DRIVER: "sqlite3"
      FATHOM_DATABASE_NAME: "fathom.db"
      FATHOM_SECRET: "<your-secret-string>" # Replace with a secure secret

volumes:
  fathom_data:

Explanation:

  • version: Specifies the Docker Compose file version.
  • services: Defines the services that make up the application.
  • fathom: Defines the Fathom Analytics service.
    • image: Specifies the Docker image to use (official Fathom image).
    • ports: Maps the container’s port 8080 to the host’s port 8080.
    • volumes: Mounts a named volume fathom_data to the /opt/fathom directory in the container, ensuring data persistence.
    • environment: Sets environment variables for Fathom configuration. Replace <your-secret-string> with a secure, randomly generated string.
  • volumes: Defines the named volume fathom_data.

To deploy, save the above content as docker-compose.yml in a directory. Then, run:

docker-compose up -d

This command will download the Fathom image, create the container, and start it in detached mode. You can then access Fathom via http://your_server_ip:8080. You’ll still need to set up a reverse proxy (like Nginx) with SSL for production use, as outlined in the original article, but this simplifies the initial Fathom deployment and upgrades.

Benefits:

  • Simplified deployment: One command to deploy the entire application.
  • Reproducibility: Consistent deployment across different environments.
  • Isolation: Fathom runs in a container, isolated from the host system.
  • Easy updates: Updating Fathom is as simple as pulling the latest image and restarting the container.

2. Using a Cloud Provider’s Container Service (e.g., AWS ECS, Google Cloud Run, Azure Container Apps):

Cloud providers offer managed container services that abstract away much of the infrastructure management required for running Docker containers. These services handle scaling, load balancing, and monitoring, making it easier to deploy and maintain Fathom Analytics in a production environment.

Example (Conceptual – Specific steps vary by provider):

  1. Create a Docker image: You can use the official Fathom image (usefathom/fathom:latest) or build your own custom image with specific configurations.
  2. Push the image to a container registry: Push the Docker image to a registry like Docker Hub, AWS ECR, Google Container Registry, or Azure Container Registry.
  3. Create a container service instance: Configure the cloud provider’s container service (e.g., AWS ECS, Google Cloud Run, Azure Container Apps) to deploy the Docker image.
  4. Configure environment variables: Set the required environment variables (e.g., FATHOM_SECRET, FATHOM_DATABASE_DRIVER, FATHOM_DATABASE_NAME) through the container service’s configuration.
  5. Configure networking and load balancing: Configure the container service to expose Fathom’s port (8080) and set up a load balancer to distribute traffic across multiple instances (if scaling is needed).
  6. Configure SSL/TLS: Use the cloud provider’s SSL/TLS certificate management services (e.g., AWS Certificate Manager, Google Managed SSL Certificates, Azure App Service Managed Certificates) to secure the connection to Fathom.

Benefits:

  • Managed infrastructure: The cloud provider handles infrastructure management, reducing operational overhead.
  • Scalability: Easily scale Fathom Analytics to handle increased traffic.
  • High availability: Cloud providers offer built-in features for high availability and fault tolerance.
  • Cost optimization: Pay only for the resources you use.

While these solutions might involve a steeper initial learning curve compared to the manual installation, they offer significant advantages in terms of scalability, maintainability, and ease of management, particularly for production deployments of Install Fathom Analytics on Ubuntu 22.04.