Understanding and analyzing website traffic is essential for businesses and website owners to make informed decisions and optimize user experiences. One popular tool for this purpose is Umami, an open-source web analytics tool that offers simplicity, privacy, and insightful data tracking.
While many analytics platforms rely on third-party services and cloud hosting, Umami offers the option of self-hosting, providing users with greater control over their data and ensuring compliance with data protection laws.
Self-hosting Umami allows you to maintain full ownership and control of your analytics data. By hosting Umami on your own servers, ensuring that sensitive information remains within your own infrastructure, reducing the risk of unauthorized access.
In this guide, I will walk you through the process of self-hosting Umami for website analytics,
Prerequisites
In order to self-host Umami, you will need these prerequisites :
- PostgreSQL or MySQL database;
- Linux Server to host the application;
The Database
In this guide, I will be using PostgreSQL for the database. Let’s start with creating the database.
CREATE DATABASE umamianalyticsdb;
Then, we will to create a user.
CREATE USER umamianalytics WITH ENCRYPTED PASSWORD 'YOUR PASSWORD';
Finally, we will grant our user all the privileges to our database.
GRANT ALL PRIVILEGES ON DATABASE umamianalyticsdb TO umamianalytics;
Installing Umami
We will be installing Umami from the source. You can either download the source code directly from github or clone the repository. In this guide I will be cloning the repository in my /applications
folder.
cd /applications
git clone https://github.com/umami-software/umami.git
cd umami
We will install Node.js 18
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
Then we will install yarn
npm install -g yarn
Now we can download the dependencies and build Umami using yarn. This will connect to the database and create the required tables and setup the admin account.
yarn install
yarn build
Starting Umami
Now that we build the application, we can run it.
yarn start
By default, the application runs on http://localhost:3000 and login with username: admin and password: umami.
Setting up a reverse proxy (NGINX)
First create a NGINX server block.
server {
server_name analytics.YOURDOMAIN.TLD;
location / {
proxy_pass http://<UMAMI_SERVER_IP>: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;
}
}
We can check that the configuration is valid.
nginx -t
If the configuration is OK we can restart NGINX for the changes to take effect.
service nginx restart
You can use certbot to add SSL support.
certbot --nginx -d analytics.YOURDOMAIN.TLD