Ubuntu builds statistics website Umami statistics

Umami is a simple, fast, privacy-focused alternative to Google Analytics

Official docker image address: https://docker.umami.dev/umami-software/umami:postgresql-latest

UMAMI 基于Node.js 开发,并且支持 MySQL 或 Postgresql 等数据库存储方式,可以将数据掌握在自己手中。并且 UMAMI 还提供了非常详细的流量分析可视化的界面,UI 体验以及统计准确度十分不错。UMAMI目前还可以防止被广告屏蔽插件等等屏蔽,统计精准度大。

Official documentation: A detailed getting started guide can be found athttps://umami.is/docs/turn up


  • Website analysis: Umami can track and analyze website traffic, page views, user behavior and other indicators to help you understand how users interact with your website.
  • Event tracking: It supports tracking of specific events, such as button clicks, form submissions, video playback, etc., so that you can understand the specific actions of users on the website.
  • User insights: Through Umami, you can obtain information about users, such as visit frequency, the ratio of new users to returning users, etc., to gain an in-depth understanding of your user group.
  • Source analysis: Umami can track the source of users visiting the website, including search engines, social media, direct visits, etc., to help you evaluate the effectiveness of marketing channels.
  • Custom reports: Based on your needs, Umami allows you to create customized reports and charts for better analysis and visualization of data.
  • A/B testing support: Umami can help you conduct A/B testing to compare different versions of pages or features to optimize the user experience of your website.
  • Data export: You can export data to CSV or other formats for integration and further analysis with other tools or analytics platforms.
  • Easy to use: Umami has a user-friendly interface and easy setup, making it relatively easy to get started even for non-technical people.
  • Open source and free: As an open source project, Umami is free to use, and you can customize and extend it according to your needs.
  • Data Privacy: Umami values the privacy of user data and does not collect sensitive information or use it for advertising purposes.
  • Lightweight: Its design is relatively simple and will not have a significant impact on the performance of the website. It is suitable for small and medium-sized websites and projects.
  • Flexible customization: Since it is open source, you can secondary develop and customize Umami according to your own needs to meet specific analysis requirements.
  • Real-time data: Umami provides real-time data monitoring and feedback, allowing you to understand website dynamics and user behavior in a timely manner.


  • 具有 Node.js 版本 12 或更高版本的服务器
  •  Umami supports MySQL and Postgresql databases.

Install Node.js on Ubuntu and update npm to the latest version

Install Node.js

NodeSource will continue to maintain the following schemas and may add others in the future.

  • amd64(64-bit)
  • f(ARM 32-bit hard floating point, ARMv7 and above:arm-linux-gnueabihf)
  • arm64(ARM 64-bit, ARMv8 and above:aarch64-linux-gnu)

Node project website:https://github.com/nodesource/distributions


Update system

sudo apt update && sudo apt upgrade

Install dependencies

sudo apt install wget curl nano ufw software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release debian-archive-keyring unzip -y


Node.js v21.x

Install the latest npm through the official package provided by NodeSource

Node.js currently has three versions, Node.js 18.x, Node.js 20.x, Node.js 21.x

The following is the installation of Node.js 20.x, which can be done with one line of code. &&\ means that after the previous command is executed correctly, the following code will be executed.

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - &&\ sudo apt-get install -y nodejs

Install as root

curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ apt-get install -y nodejs

If you install other versions, just replace setup_20.x in the above command with the version you want to install.

Node official website download address:https://nodejs.org/en/download/


sudo apt update sudo apt install nodejs # does not come with npm, you need to install it yourself sudo apt install npm # upgrade npm sudo npm install npm -g # use n Node version management tool to upgrade to the latest version sudo npm install n -g # download the latest stable version sudo n stable # Download the latest version sudo n lastest # View the downloaded version sudo n ls # Switch Node version sudo n 18.21.1

卸载nodejs Ubuntu 和 Debian 软件包

apt-get purge nodejs &&\ rm -rf /etc/apt/sources.list.d/nodesource.list &&\ rm -rf /etc/apt/keyrings/nodesource.gpg

Install Yarn

Because this project uses Yarn for compilation, we need to install Yarn.

npm install -g yarn

Create a new MySQL database

Here we are using MySQL and create a new empty database in the database

Use phpmyadmin to create an empty Umami database on the server


Or create it directly on the server:

mysql -u root -p umami < sql/schema.mysql.sql

Install Umami


Download and install Umami

Customize the download to the /home/umami directory. You can also place it in other directories.

cd /home/ #git pull umami git clone https://github.com/umami-software/umami.git # enter the umami directory cd umami # install yarn install

自建统计网站Umami统计-1Wait patiently. After the installation is complete, you need to configure the .env file.

Configuration .env file

Create a new file named .env in the umami folder.

Use the touch command to create a new .env file, or directly use the vim command to create a new .env file.


Note that after the .env file is created, it cannot be viewed in the directory. .env is a hidden file and can be edited directly using vi.

Edit the .env file and enter the following configuration to save:

DATABASE_URL=mysql://username:password@localhost:3306/database nameAPP_SECRET=bu4orqfdlG+Dh3Otau4oWSBbI9kGWSkGfYc/WiH/ DISABLE_TELEMETRY=1 TRACKER_SCRIPT_NAME=custom
  • DATABASE_URL: Just fill in the database parameters we configured previously according to the instructions.
  • HASH_SALT: Just fill in random characters for encryption.
  • TRACKER_SCRIPT_NAME: The custom js file name of the statistics link. Enter whatever name you like. Do not use Chinese, and do not add .js after it.

Example of linking two databases

postgresql://username:mypassword@localhost:5432/mydb mysql://username:mypassword@localhost:3306/mydb

Compile Umami

yarn build

Just wait until he finishes executing.

If you encounter an error that cannot connect to the database

$ node scripts/check-db.js
✓ DATABASE_URL is defined.
✗ Unable to connect to the database.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "check-db" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Change localhost to

DATABASE_URL=mysql://username:password@ nameAPP_SECRET=bu4orqfdlG+Dh3Otau4oWSBbI9kGWSkGfYc/WiH/ DISABLE_TELEMETRY=1 TRACKER_SCRIPT_NAME=custom

Uninstall Umami

If some irreversible operations occur during the installation process, you can uninstall Umami and reinstall it. Delete the Umami installation directory.

rm -rf /home/umami reboot

Start application

Commonly usedyarn startIt can be started directly, but it will stop running directly after exiting ssh, so you need to use some tools to ensure background running. The recommendation in the official documentation is to install the PM2 manager.

npm install pm2 -g sudo yarn global add pm2 cd /home/umami pm2 start npm --name umami -- start pm2 startup pm2 save


If no errors are displayed, the installation is successful. Test whether the local is opened normally.


Check to see if there is any data output.

自建统计网站Umami统计-1Check the current status of port 3000. If port 3000 is not occupied, then umami should not be started.

lsof -i:3000

Using your server IP + port, open Umami in your browser


Log in using the system default username and password

  • Username: admin
  • Password:umami


The page is very simple and elegant, go and set up yourBar! After adding the website, you can get the code and start statistics!

Remember to change the password in your personal information, the password setting is a bit complicated!


PM2 uninstall

# prohibits starting PM2 at boot pm2 unstartup # kills the daemon pm2 kill # uninstalls npm remove pm2 -g # deletes all saved configurations and logs rm -rf ~/.pm2

Finally, after the deletion is completed, go to /usr/local/lib/node_modules/ to see if there is a pm2 folder. If there is, just delete it directly.

OpenLiteSpeed as reverse proxy server

Create a new virtual host in OpenLiteSpeed, and then go to this host to create a newexternal application , type select network server, name writetongji , write the address, you can write public IP:3000




Then create a resource set, select Proxy as the type, and set the URI to /





Note: The network server selects the previously created tongji, and other settings are filled in to the maximum.

Rewrite rules, because the front-end and back-end domain names are different, so pseudo-static rules must be used to pass the domain name to the back-end. Otherwise, the back-end will refuse the connection, and the front-end will directly return a 403 or 500 error.


RewriteRule ^/(.*)$ http://tongji/$1 [P,E=Proxy-Host:xxx.com]
注意 其中 tongji 是 第二步里的外部应用程序名称, xxx.com是反向代理的域名。
If you install the CyberPanel panel, the rewrite rules will prompt Disabled by CyberPanel. You need to fill in the rewrite rules in the website corresponding to the CyberPanel panel.
Finally, restart OpenLiteSpeed and you can access it normally.

Configure Chinese

After we log in to the backend, it may default to English, and the panel comes with Simplified Chinese. Open Settings–>Profile–>Language and select Chinese.

Upgrade update umami

There is an update about umami. Please pause pm2 first and then execute the following code to update and then run it again:

pm2 stop umami # enter the umami file directory cd /home/umami git pull yarn install yarn build

At this point, the umami construction is officially over. The rest of the configuration is very simple. We only need to follow the instructions on the umami panel. If you don’t understand, please leave a message in the comment area.

Reference article:https://www.howtoforge.com/how-to-install-umami-analytics-on-debian-12/

5/5 - (1 vote)

Leave a Reply

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