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
Let’s start with creating the database (PostgreSQL and MySQL).
CREATE DATABASE umamianalyticsdb;
Then, we will to create a user.
PostgreSQL:
CREATE USER umamianalytics WITH ENCRYPTED PASSWORD 'YOUR PASSWORD';
MySQL
CREATE USER umamianalytics IDENTIFIED BY 'YOUR PASSWORD';
Finally, we will grant our user all the privileges to our database.
PostgreSQL:
GRANT ALL PRIVILEGES ON DATABASE umamianalyticsdb TO umamianalytics;
MySQL
GRANT ALL ON umamianalyticsdb.* TO umamianalytics;
FLUSH PRIVILEGES;
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
Add Database configuration. Create .env file with the following content
PostgreSQL
DATABASE_URL=postgresql://umamianalytics:<POSTGRESQL PASSWORD>@localhost:5432/umamianalyticsdb
MySQL
DATABASE_URL=mysql://umamianalytics:<MYSQL PASSWORD>@localhost:3306/umamianalyticsdb
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.
Keep Umami running
To keep the process running we can use systemd. let’s create the service file :
nano /etc/systemd/system/umami.service
[Unit]
Description=Umami Server
[Service]
ExecStart=yarn start
WorkingDirectory=/applications/umami
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=umami
[Install]
WantedBy=multi-user.target
Then enable the service and start it
sudo systemctl daemon-reload
sudo systemctl enable umami
sudo systemctl start 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