Understanding your website’s performance is paramount for informed decision-making. Among the myriad of analytics tools available, Fathom Analytics stands out for its simplicity, privacy focus, and powerful insights. If you’re operating on a Debian 12 system and seeking a streamlined process to integrate Fathom Analytics into your website, you’re in the right place. In this guide, we’ll walk you through the step-by-step installation process, enabling you to effortlessly harness the capabilities of Fathom Analytics while maintaining the robust security and stability offered by Debian 12.
First, make sure you’ve set up a VPSie Account if you haven’t already, then proceed to Deploy the Debian 12 server based on your specific needs.
Before installing any packages, it’s crucial to update your system’s package list to ensure access to the latest versions. Open a terminal and run the command:
sudo apt-get update -y
Install Dependencies
Install Dependencies
To set up your environment, run the command below. This will install PostgreSQL server, Nginx web server, Certbot, Nginx Certbot plugin, and UFW (Uncomplicated Firewall).
sudo apt install postgresql nginx certbot python3-certbot-nginx ufw
Confirm the status of the PostgreSQL service by executing the following command to ensure it’s both operational and enabled.
sudo systemctl is-enabled postgresql
sudo systemctl status PostgreSQL
Please confirm the status of the nginx service by running the command provided below.
sudo systemctl is-enabled nginx
sudo systemctl status nginx
Confirm the Certbot installation, The following command will find the Certbot binary executable and display the current version installed on your system:
which certbot
certbot --version
Configure UFW Firewall
Configure UFW Firewall
To open ports for SSH, HTTP, and HTTPS protocols, run the following command:
sudo ufw allow OpenSSH
sudo ufw allow "WWW Full"
Please execute the following command to initiate and activate UFW on your Debian system.
sudo ufw enable
Finally, confirm the UFW status by executing the following command.
sudo ufw status
Configure PostgreSQL Database
Run the following command to log in to the PostgreSQL server.
sudo -u postgres psql
To create a new database named fathomdb and a user named fathom with a secure password in PostgreSQL, you can use the following queries. Remember to replace your_secure_password with your desired password.
CREATE USER fathom WITH CREATEDB CREATEROLE PASSWORD 'your_secure_password';
CREATE DATABASE fathomdb OWNER fathom;
Now, run the following queries to check the list of available databases and users on the PostgreSQL server.
\du
\l
After creating the database and user, execute the following command to log in to PostgreSQL with the user fathom and the database fathomdb. When prompted, enter the password for your database user.
sudo -u postgres psql -U fathom -h 127.0.0.1 -d fathomdb
After connecting to the PostgreSQL server, run the following query to verify your connection.
\conninfo
Download Fathom
Visit the Fathom GitHub page to find the download URL for the Fathom binary package. Once you have the URL, you can use the wget command to download it.
wget [URL]
For instance, to download Fathom version 1.3.1, you can use the following command:
wget https://github.com/usefathom/fathom/releases/download/v1.3.1/fathom_1.3.1_linux_amd64.tar.gz
After downloading, unzip the Fathom binary package into the directory /usr/local/bin/fathom and ensure it has executable permissions.
tar -C /usr/local/bin -xzf fathom_1.3.1_linux_amd64.tar.gz
chmod +x /usr/local/bin/fathom
Execute the command below to confirm the location of the fathom binary file and the version currently downloaded.
which fathom
fathom --version
Integrating Fathom with PostgreSQL
To establish a new system user named fathom, who will manage your Fathom installation, enter the command below.
sudo useradd -r -d /opt/fathom fathom
Create a new home directory named /opt/fathom and assign ownership to the user fathom.
sudo mkdir -p /opt/fathom
sudo chown -R fathom:fathom /opt/fathom
To generate a random secret for Fathom, execute the command below. Remember to save the output as you’ll require it to secure Fathom.
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20 ; echo ''
Navigate to /opt/fathom
cd /opt/fathom
Now, create a new /opt/fathom/data directory and a new file /opt/fathom/data/.env using the following command.
sudo -u fathom mkdir -p /opt/fathom/data
sudo -u fathom nano /opt/fathom/data/.env
Please incorporate the below configuration, ensuring to modify the specifics of the PostgreSQL database name, user, and password.
FATHOM_GZIP=true
FATHOM_DEBUG=true
FATHOM_DATABASE_DRIVER="postgres"
FATHOM_DATABASE_NAME="fathomdb"
FATHOM_DATABASE_USER="fathom"
FATHOM_DATABASE_PASSWORD="your_secure_password"
FATHOM_DATABASE_HOST="127.0.0.1"
FATHOM_DATABASE_SSLMODE="disable"
FATHOM_SECRET="BWTtur9A1qWtXG6656q4"
Save and exit the file.
Execute the following command to verify that your Fathom configuration is successful.
cd /opt/fathom/data
sudo -u fathom fathom server
Configure Fathom as Systemd Service
Generate a fresh systemd service file named /etc/systemd/system/fathom.service by executing the subsequent command in the nano editor.
sudo nano /etc/systemd/system/fathom.service
Insert 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 the file.
Execute the following systemctl command to refresh the systemd manager and implement the modifications you’ve made.
sudo systemctl daemon-reload
Now, execute the systemctl command below to start and enable the fathom service.
sudo systemctl start fathom
sudo systemctl enable fathom
Confirm the functionality of the fathom service by executing the command provided below.
sudo systemctl is-enabled fathom
sudo systemctl status fathom
Configure Fathom Administrator User
Navigate your current working directory to /opt/fathom/data.
cd /opt/fathom/data
Use the command below to establish an administrator user for your Fathom setup. Remember to update the email address and password with the provided command.
sudo -u fathom fathom user add --email="[email protected]" --password="your_secure_password"
Configure Nginx as a Reverse Proxy
Using the nano editor, create a fresh Nginx server block configuration named fathom in the directory /etc/nginx/sites-available with the command provided.
sudo nano /etc/nginx/sites-available/fathom
Please add the provided configuration and ensure to update the domain name within the server_name option.
server {
listen 80;
server_name analytics.menon.fun;
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 exit the file.
Please execute the following command to activate the server block file located at /etc/nginx/sites-available/fathom and ensure the correctness of Nginx syntax.
sudo ln -s /etc/nginx/sites-available/fathom /etc/nginx/sites-enabled/
sudo nginx -t
Next, run the following command to restart the Nginx service and apply the changes that you’ve made.
sudo systemctl restart nginx
Access Fathom Web Interface
Open your favorite web browser and navigate to the domain where your Fathom installation is located, like http://analytics.menon.fun/.
You’ll need to check out the tracker code that Fathom generated and Take a look at your analytics page.
So, in a nutshell, remember to check out your site’s Fathom Analytics dashboard regularly and keep your analytics data safe and sound. It’s like keeping an eye on your site’s pulse and making sure its secrets stay under lock and key!