How to Install Fathom Analytics on Ubuntu 18.04 LTS
This tutorial exists for these OS versions
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 18.04 (Bionic Beaver)
On this page
Fathom is a self-hosted open source web analytics platform that provides simple, useful website statistics without tracking or storing your users' personal information. It is a very good alternative to Google Analytics with a simple web interface that can be used for small and medium businesses. Fathom gives you full control over your data without using third-party solutions. Fathom offers you top pages, top referrers, bounce rate and average time spent on your website.
In this tutorial, we will learn how to install Fathom analytics on Ubuntu 18.04 server.
Requirements
- A server running Ubuntu 18.04.
- A static IP address 192.168.0.103 is setup to your server.
- A root password is setup to your server.
Getting Started
Before starting, you will need to update your system with the latest version. You can do this by running the following command:
apt-get update -y
apt-get upgrade -y
Once your server is updated, restart your server to apply the changes.
Install Nginx and MariaDB
First, you will need to install Nginx and MariaDB server to your server. You can install them by running the following command:
apt-get install nginx mariadb-server -y
Once both package are installed, start MariaDB and Nginx service and enable them to start on boot time with the following command:
systemctl start nginx
systemctl start mariadb
systemctl enable nginx
systemctl enable mariadb
Configure MariaDB
By default, MariaDB is not secured. So, you will need to secure it. You can do this by running the mysql_secure_installation script:
mysql_secure_installation
This script will change your current root password, remove anonymous users, disallow root login remotely as shown below:
Enter current password for root (enter for none): Set root password? [Y/n]: N Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
Once the MariaDB is secured, log in to MariaDB shell with the following command:
mysql -u root -p
Enter your root password, then create a database and user for fathom with the following command:
MariaDB [(none)]> CREATE DATABASE fathom;
MariaDB [(none)]> CREATE USER 'fathomuser'@'localhost' IDENTIFIED BY 'password';
Next, grant all the privileges to fathom database with the following command:
MariaDB [(none)]> GRANT ALL ON fathom.* TO 'fathomuser'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
Next, flush the privileges and exit from the MariaDB shell with the following command:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]>EXIT;
Install and Configure Fathom
First, you will need to download the latest version of Fathom binary from Git repository. You can download it with the following command:
wget https://github.com/usefathom/fathom/releases/download/latest-development/fathom-linux-amd64
Once the download is completed, move the downloaded binary to the /usr/local/bin/ directory with the following command:
mv fathom-linux-amd64 /usr/local/bin/fathom
Next, provide executable permission to fathom binary with the following command:
chmod 755 /usr/local/bin/fathom
Next, you will need to configure Fathom evironment in your home directory. You can do this by running the following command:
nano .env
Add the following lines:
FATHOM_SERVER_ADDR=9000 FATHOM_DEBUG=true FATHOM_DATABASE_DRIVER="mysql" FATHOM_DATABASE_NAME="fathom" FATHOM_DATABASE_USER="fathomuser" FATHOM_DATABASE_PASSWORD="password" FATHOM_DATABASE_HOST="localhost" FATHOM_DATABASE_SSLMODE="" FATHOM_SECRET="random-secret-string"
Next, you will need to create an administrator account for Fathom. You can do it with the following command:
fathom --config=.env user add [email protected] --password=admin@123
You should see the following output:
INFO[0000] Fathom 1.1.0 INFO[0000] Configuration file: /root/.env INFO[0000] Connected to mysql database: fathomuser:password@tcp(localhost)/fathom?loc=Local&parseTime=true INFO[0000] Created user [email protected]
Now, start the Fathom server with the following command:
fathom server
You should see the following output:
INFO[0000] Fathom 1.1.0 INFO[0000] Configuration file: /root/.env INFO[0000] Connected to mysql database: fathomuser:new_password_here@tcp(localhost)/fathom?loc=Local&parseTime=true INFO[0002] Applied 11 database migrations! INFO[0002] Server is now listening on :9000
Access Fathom Web Interface
Fathom is now starting and listening on port 9000. Open your web browser and type the URL http://192.168.0.103:9000. You will be redirected to the following page:
Now, provide your administrator credential and click on the Sign in button. You should see the following page:
Now, provide your Site name and click on the Create site button. You should see the following page:
Example Statistics:
Create Fathom Systemd Service File
Next, you will need to create a systemd service file for Fathom to manage Fathom service. You can do it with the following command:
nano /etc/systemd/system/fathom.service
Add the following lines:
[Unit] Description=Fathom server management service unit Requires=network.target After=network.target [Service] Type=simple User=root Restart=always RestartSec=3 WorkingDirectory=/root ExecStart=/usr/local/bin/fathom server [Install] WantedBy=multi-user.target
Save and close the file, then enable Fathom service with the following command:
systemctl daemon-reload
systemctl enable fathom
Next, start Fathom service with the following command:
systemctl start fathom
You can check the status of Fathom service with the following command:
systemctl status fathom
You should see the following output:
? fathom.service - Fathom server management service unit Loaded: loaded (/etc/systemd/system/fathom.service; disabled; vendor preset: enabled) Active: active (running) since Wed 2019-01-30 11:44:46 UTC; 4s ago Main PID: 19671 (fathom) Tasks: 5 (limit: 1114) CGroup: /system.slice/fathom.service ??19671 /usr/local/bin/fathom server Jan 30 11:44:46 ubuntu1804 systemd[1]: Started Fathom server management service unit. Jan 30 11:44:46 ubuntu1804 fathom[19671]: time="2019-01-30T11:44:46Z" level=info msg="Fathom 1.1.0" Jan 30 11:44:46 ubuntu1804 fathom[19671]: time="2019-01-30T11:44:46Z" level=info msg="Configuration file: /root/.env" Jan 30 11:44:46 ubuntu1804 fathom[19671]: time="2019-01-30T11:44:46Z" level=info msg="Connected to mysql database: fathomuser:new_password_here@tcp(loc Jan 30 11:44:46 ubuntu1804 fathom[19671]: time="2019-01-30T11:44:46Z" level=info msg="Server is now listening on :9000"
Configure Nginx as a Reverse Proxy
By default, Fathom listening on port 9000. So you will need to configure Nginx as a reverse proxy to access Fathom without specifying port number.
You can do this by creating Fathom virtual host file:
nano /etc/nginx/sites-available/fathom
Add the following lines:
server { listen 80; listen [::]:80; server_name 192.168.0.103; location / { proxy_pass http://localhost:9000/; } }
Save and close the file. Then, test Nginx for any syntax error with the following command:
nginx -t
Next, disable Nginx default virtual host file and enable Fathom virtual host file with the following command:
rm -rf /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/fathom /etc/nginx/sites-enabled/
Next, restart Nginx service with the following command:
systemctl restart nginx
Now, you can access your Fathom web interface using the URL http://192.168.0.103.