DEV Community

Cover image for How to Deploy Umami Analytics on Ubuntu 24.04 VPS with PostgreSQL & PM2
Faysal Molla
Faysal Molla

Posted on Originally published at faysal.cloud

How to Deploy Umami Analytics on Ubuntu 24.04 VPS with PostgreSQL & PM2

Why Google Analytics 4 is Hurting Your Website

Google Analytics 4 (GA4) has become a frustrating burden for webmasters and privacy-conscious businesses. Between confusing interface redesigns, data sampling thresholds, and complex regulatory crackdowns in the European Union (where Austrian, French, and Danish data protection authorities have ruled GA non-compliant with GDPR), running GA requires annoying cookie consent banners that degrade conversion rates.

Furthermore, because Google's tracking domains are globally flagged, over 30% to 45% of your tech-savvy visitors block GA completely via uBlock Origin, Brave Browser, or Pi-hole. You are flying blind.

Umami is an open-source, privacy-focused alternative written in Next.js and Prisma. It collects no personally identifiable information (PII), uses no cookies, complies fully with GDPR without annoying consent banners, and ships a tracking script weighing less than 2 KB.

Server Requirements on Hostinger or Contabo VPS

Umami is exceptionally resource-efficient. An entry-level Hostinger KVM 1 or Contabo Cloud VPS 1 running Ubuntu 24.04 LTS can effortlessly track over 5 million monthly pageviews while consuming under 500MB of RAM.

Step 1: Install Node.js 20 LTS and PostgreSQL 16

SSH into your VPS and install Node.js, Git, and PostgreSQL:

ssh root@YOUR_SERVER_IP
apt update && apt upgrade -y
apt install -y curl git build-essential ufw postgresql postgresql-contrib

# Install Node.js 20 LTS via NodeSource
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
npm install -g pm2
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure PostgreSQL Database

Switch to the PostgreSQL user and create a dedicated database and user for Umami:

sudo -u postgres psql

CREATE DATABASE umami;
CREATE USER umamiuser WITH ENCRYPTED PASSWORD 'StrongSecurePassword_7731!';
GRANT ALL PRIVILEGES ON DATABASE umami TO umamiuser;
ALTER DATABASE umami OWNER TO umamiuser;
\q
Enter fullscreen mode Exit fullscreen mode

Step 3: Clone Umami and Build the Application

Clone the latest stable release of Umami from GitHub:

cd /var/www
git clone https://github.com/umami-software/umami.git
cd umami
npm install
Enter fullscreen mode Exit fullscreen mode

Create the .env environment file:

nano .env
Enter fullscreen mode Exit fullscreen mode

Add the database connection string and a random hash salt:

DATABASE_URL=postgresql://umamiuser:StrongSecurePassword_7731!@localhost:5432/umami
APP_SECRET=GenerateRandomString32CharactersLong!
Enter fullscreen mode Exit fullscreen mode

Build the Next.js production bundle:

npm run build
Enter fullscreen mode Exit fullscreen mode

Step 4: Manage the Process with PM2

Launch Umami with the PM2 process manager to ensure automatic restarts upon reboot:

pm2 start npm --name "umami" -- run start
pm2 save
pm2 startup
Enter fullscreen mode Exit fullscreen mode

Run the output command provided by pm2 startup to register the systemd service.

Step 5: Nginx Reverse Proxy with SSL

Expose Umami securely over HTTPS via Nginx:

apt install -y nginx certbot python3-certbot-nginx

cat << 'EOF' > /etc/nginx/sites-available/umami.conf
server {
    server_name analytics.yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
EOF

ln -s /etc/nginx/sites-available/umami.conf /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
certbot --nginx -d analytics.yourdomain.com --non-interactive --agree-tos -m admin@yourdomain.com
Enter fullscreen mode Exit fullscreen mode

Step 6: Adding the Tracking Tag to Your Website

Navigate to https://analytics.yourdomain.com. Log in with default credentials:

  • Username: admin

  • Password: umami

(Immediately change this default password under Settings > Profile!)

Click Add Website, input your site name and domain, and Umami generates your unique tracking snippet:

<script defer src="https://analytics.yourdomain.com/script.js" data-website-id="your-unique-uuid-here"></script>
Enter fullscreen mode Exit fullscreen mode

Add this single script tag to your WordPress header, Next.js root layout, or HTML head. Because the script originates from your own first-party domain, browser ad-blockers will not block it, granting you 100% accurate traffic data with zero privacy liability.


Originally published at faysal.cloud.

Top comments (0)