Advance

How to Install and Uninstall Umami on Ubuntu 20.04

Richard 16 Min Read
How to Install and Uninstall Umami on Ubuntu 20.04

Umami is an open source web analytics program. It focuses on simplicity, is well-designed, fast and privacy-focused. Umami is written in Node.js and is a self-hosted web analytics alternative to Google Analytics that focuses on privacy. Umami can store data about your website visitors in a MySQL or PostgreSQL database. In this article, we are going to teach you How to Install and Uninstall Umami on Ubuntu 20.04. You can visit the packages available in Eldernode if you wish to purchase a Linux VPS server.

Tutorial Install and Uninstall Umami on Ubuntu Linux

Install Umami on Ubuntu 20.04 | Ubuntu 21.04

The repository will be downloaded in the /opt folder.

cd /opt

Now you should clone the repository from GitHub by entering the following command:

sudo git clone https://github.com/mikecao/umami.git

All the software and configuration files will be located in /opt/umami. Then go to the newly created umami directory:

cd umami

At this step, you need to update the project docker-compose.yml file. This file is what it uses to configure and launch multiple Docker containers simultaneously. You have to change two options in this file: The IP that Umami binds to, and a random hash that is used as salt when encrypting things in the database.

Next step, generate a new random hash to paste into the file. To do this, enter the following command:

openssl rand -base64 32

The openssl command is used to generate 32 random characters. You should first copy the output to your clipboard and then open the configuration file with the following command:

sudo nano docker-compose.yml

Now you should find the HASH_SALT option and delete the placeholder text. Then remember to paste in the random hash by entering the following command:

HASH_SALT: replace-me-with-a-random-string

Then you should find the ports:

ports: - "127.0.01:3000:3000"

To update the value “3000:3000”, you should just add 127.0.0.1: to it. This ensures that Umami is not publicly available and only listens on the localhost interface.

Even with a UFW firewall set up, due to some quirks in how the Docker network works if you did not do this step, your Umami container would be available to the public on port 3000.

Now you should save the file by pressing on CTRL+O and then ENTER in nano. Finally, close out of your editor by pressing on CTRL+X.

At this stage, you need to set up your two containers. To do this, you can use the following command:

sudo docker-compose up --detach

Docker-compose create containers in the background, detached from the terminal session by announcing the –detach flag:

Creating umami_db_1 ... done
Creating umami_umami_1 ... done

You can verify to fetch the homepage of your new Umami container running on localhost by using the following command:

curl localhost:3000

Output:

<!DOCTYPE html><html><head><meta charSet="utf-8"/> . . .

If a large chunk of HTML is output to your terminal, it indicates that the Umami server is up and running.

Configure Nginx on Ubuntu Linux

First, update your package list with the following command:

sudo apt update

and now you can install Nginx by entering the following command:

sudo apt install nginx

Next, you need to allow ports 80 and 443 for traffic. To do this, use the “Nginx Full” UFW application profile:

sudo ufw allow "Nginx Full"

Output:

Rule added
Rule added (v6)

Now you should open a new Nginx configuration file in the /etc/nginx/sites-available directory:

sudo nano /etc/nginx/sites-available/umami.conf

Then paste the following into the new configuration file. Remember to replace your_domain_here with the domain you configured to point to your Umami server.

server {      listen        80;      listen        [::]:80;      server_name  your_domain_here;        access_log  /var/log/nginx/umami.access.log;      error_log   /var/log/nginx/umami.error.log;        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;    }  }

The above configuration is HTTP-only, as you allow Certbot to configure SSL in the next step. The configuration of logging locations is set up and then passes all traffic to http://localhost:3000.

Now you should save the file and close it.

Then you need to link the configuration to /etc/nginx/sites-enabled/ to enable it. To do this, enter the following command:

 sudo In -s /etc/nginx/sites-available/umami.conf /etc/nginx/sites-enabled/

In this step, verify the correct syntax of the configuration file by executing the following command:

sudo nginx -t

Output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, you have to reload the nginx service to pick up the new configuration. To do this, run the following command:

sudo systemctl reload nginx

Umami site is available with simple HTTP. If you load http://your_domain_here.

How to Install Certbot and Set up SSL Certificates

First, you should install Certbot and its Nginx plugin by entering the following command:

sudo apt install certbot python3-certbot-nginx

You should run certbot in –nginx mode and specify the same domain that you used in the Nginx server_name configuration. To do this, use the following command:

sudo certbot --nginx -d your_domain_here

Now you should agree to the Let’s Encrypt terms of service and enter your email address.

Then you can redirect all HTTP traffic to HTTPS, which is safe to do.

Next, Let’s Encrypt confirm your request and your certificate will be downloaded by Certbot.

You should test your configuration at:

https://www.ssllabs.com/ssltest/analyze.html?d=umami.example.com

Nginx is automatically reloaded by Certbot to pick up the new configuration and certifications. Now reload your site and if you select the redirect option, it will automatically switch you over to HTTPS.

 

How to Uninstall Umami on Ubuntu 20.04 | Ubuntu 21.04

Umami will be removed from your system by entering the following command.

sudo apt-get remove umami

Conclusion

In this article, you learned how to install and uninstall umami on Ubuntu 20.04. In fact, The Umami application and the PostgreSQL database were launched using Docker Compose, Then an Nginx reverse proxy was launched. Finally, you were able to secure it with Let’s Encrypt SSL certificates.

View More Posts
Richard
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day