Umami Analytics is a lightweight, open-source, self-hosted web analytics solution that serves as a privacy-focused alternative to Google Analytics and other paid analytic tools. Unlike traditional analytics tools, Umami doesn’t place any cookies on the user’s browser, eliminating the need for annoying cookie banners on your website. In this tutorial, we will guide you through the process of installing Umami Analytics on a Debian 12 server and show you how to use it to track your website’s statistics.
Prerequisites
Before we start with the installation process, make sure you have the following:
- A server running Debian 12.
- A non-root user with sudo privileges.
- A fully qualified domain name (FQDN), such as umami.example.com, pointing to your server.
- The Uncomplicated Firewall (UFW) enabled and running on your server.
To begin, let’s update your system and install some essential packages:
sudo apt update && sudo apt upgrade sudo apt install wget curl nano ufw software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release debian-archive-keyring unzip-y
Step 1 – Configure Firewall
The first step is to configure the firewall on your Debian server. By default, Debian comes with UFW (Uncomplicated Firewall). Let’s check if the firewall is running:
sudo ufw status
If the firewall is inactive, you will see the following output:
Status: inactive
To enable the firewall and allow SSH, HTTP, and HTTPS connections, run the following commands:
sudo ufw allow OpenSSH sudo ufw allow http sudo ufw allow https sudo ufw enable
Confirm that the firewall is now active by running:
sudo ufw status
You should see the following output:
Status: active To Action From -- ----- ----- OpenSSH. ALLOW Anywhere 80/tcp. ALLOW Anywhere 443. ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere(v6) 80/tcp (v6) ALLOW Anywhere(v6) 443 (v6) ALLOW Anywhere(v6)
Step 2 – Install Git
We need to install Git to clone Umami’s official repository. Run the following command to install Git:
sudo apt install git
Verify the installation by checking the Git version:
git --version
You should see the installed Git version:
git version 2.39.2
Next, we’ll set up some initial Git configuration variables:
git config --global user.name "Your Name" git config --global user.email "[email protected]"
Step 3 – Install Node
Umami is a JavaScript application that runs on Node.js. To install Node, we’ll use Nodesource’s installer. Currently, Node v16.0 is the stable version. Run the following commands to download and install Node:
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg NODE_MAJOR=18 echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list sudo apt update sudo apt install nodejs
To verify the Node installation, run:
node --version
You should see the installed Node version:
v18.18.0
Step 4 – Install MariaDB Server
Debian 12 does not come with MySQL installed by default, so we’ll use MariaDB as a replacement. Run the following command to install MariaDB:
sudo apt install mariadb-server
To check the version of MariaDB, run:
mysql --version
You should see the installed MariaDB version:
mysql Ver 15.1 Distrib 10.11.4-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
Next, run the MariaDB secure installation script to set up the root password and improve security:
sudo mariadb-secure-installation
Follow the prompts to set a root password, remove anonymous user accounts, disallow root login remotely, remove the test database, and reload the privilege tables.
Step 5 – Download Umami
Before we can install Umami, we need to install the Yarn package manager. Run the following command to install Yarn using NPM:
sudo npm install -g yarn
With Yarn installed, we can now clone Umami’s GitHub repository:
git clone https://github.com/mikecao/umami.git
Switch to the newly created Umami directory:
cd umami
Install the required Umami modules:
yarn install
Step 6 – Configure Umami
Now that Umami is downloaded, we need to create MySQL credentials and configure Umami to use the database.
First, enter the MySQL shell by running:
sudo mysql
Once inside the MySQL shell, create a user and a database for Umami:
CREATE USER 'umamiuser'@'localhost' IDENTIFIED BY 'YourPassword'; CREATE DATABASE umami; GRANT ALL PRIVILEGES ON umami.* TO 'umamiuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
Next, create a .env
file in the Umami directory to store the environment variables:
touch .env nano .env
In the .env
file, paste the following code:
DATABASE_URL=mysql://umamiuser:YourPassword@localhost:3306/umami APP_SECRET=bu4orqfdlG+Dh3Otau4oWSBbI9kGWSkGfYc/WiH/ DISABLE_TELEMETRY=1 TRACKER_SCRIPT_NAME=custom
Make sure to replace YourPassword
with the password you set for the umamiuser
in the previous step. Save and close the file.
Step 7 – Running Umami
With Umami configured, we can now build and start the application. Run the following commands:
yarn build sudo yarn global add pm2 pm2 start yarn --name umami -- start pm2 save
This will build the Umami application, start it using PM2, and save the process list.
To ensure that Umami starts automatically on system boot, run the following command:
pm2 startup
Follow the instructions to generate a startup script for PM2.
Step 8 – Install Nginx
To serve Umami over HTTPS, we’ll install Nginx as a reverse proxy. Run the following commands to install Nginx:
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list sudo apt update sudo apt install nginx
To verify the installation, run:
sudo nginx -v
You should see the installed Nginx version.
Step 9 – Install SSL using Let’s Encrypt
To secure your Umami installation with SSL/TLS, we’ll use Let’s Encrypt to generate free SSL certificates.
First, install Certbot using Snapd:
sudo apt install snapd sudo snap install core sudo snap refresh core sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot
Verify the installation by running:
certbot --version
Next, generate the SSL certificate for your Umami domain:
sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email protected] -d umami.example.com
Make sure to replace umami.example.com
with your actual domain.
To generate a Diffie-Hellman group certificate, run:
sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
Finally, check the Certbot renewal scheduler service:
sudo systemctl list-timers
You should see snap.certbot.renew.service
scheduled to run.
Step 10 – Configure Nginx
Now that we have the SSL certificate, let’s configure Nginx to serve Umami over HTTPS.
Create and open the Nginx configuration file for Umami:
sudo nano /etc/nginx/conf.d/umami.conf
Paste the following code into the file:
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name umami.example.com; access_log /var/log/nginx/umami.access.log; error_log /var/log/nginx/umami.error.log; # SSL ssl_certificate /etc/letsencrypt/live/umami.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/umami.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/umami.example.com/chain.pem; ssl_session_timeout 5m; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; resolver 8.8.8.8; location / { proxy_pass http://localhost:3000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } # enforce HTTPS server { listen 80; listen [::]:80; server_name umami.example.com; return 301 https://$host$request_uri; }
Replace umami.example.com
with your actual domain.
Save and close the file.
Next, open the Nginx main configuration file:
sudo nano /etc/nginx/nginx.conf
Add the following line before the line include /etc/nginx/conf.d/*.conf;
:
server_names_hash_bucket_size 64;
Save and close the file.
Verify the Nginx configuration file syntax:
sudo nginx -t
If there are no syntax errors, restart the Nginx service:
sudo systemctl restart nginx
Step 11 – Set up a Site and Collect Statistics
Now that Umami and Nginx are properly configured, let’s set up a website in Umami and start collecting statistics.
Open your browser and visit https://umami.example.com
(replace umami.example.com
with your actual domain). You should see the Umami login page.
Use the default administrator account with the username admin
and the password umami
to log in.
Once logged in, you will be taken to the Umami dashboard.
To add a website, go to the settings page and click on “Add website”. Enter the necessary details and save the changes.
To start collecting statistics, go to the “Tracking code” tab and copy the code. Paste this code between the header or footer HTML tags on your website.
Umami will now start tracking visitor data and providing you with insightful analytics.
Step 12 – Update Umami
To keep Umami up to date, you’ll need to periodically update it. Here’s how you can update Umami to the latest version:
cd ~/umami pm2 stop umami yarn install yarn build pm2 start umami
This will stop the Umami application, update the necessary dependencies, rebuild the application, and start it again.
Congratulations! You have successfully installed and configured Umami Analytics on your Debian 12 server. You can now track your website’s statistics in a privacy-focused manner.
Shape.host provides reliable and scalable Linux SSD VPS hosting services. Our cloud hosting solutions are designed to empower businesses with efficient and secure hosting environments. Visit our website to learn more about our services.