Back to blog
Blog

Self-Host Matomo Tag Manager on a VPS

Self-host Matomo Tag Manager on a VPS for GTM-style control without third-party scripts. Deploy with Docker, HTTPS, backups, and updates.

By Anurag Singh
Updated on Nov 29, 2026
Category: Blog
Share article
Self-Host Matomo Tag Manager on a VPS

Most tag manager setups add a new third party to every page view. You gain convenience, but you also inherit someone else’s uptime, latency, and data-handling choices. If you want Google Tag Manager-style control without pulling third-party scripts into your critical path, you can self-host Matomo Tag Manager alongside Matomo Analytics and keep the full pipeline on infrastructure you control.

This isn’t a copy-paste “one true setup.” It’s a practical deployment guide for a real VPS. It focuses on the operational pieces that usually bite later: HTTPS, reverse proxying, backups, and updates you can run with confidence.

Why you’d self-host Matomo Tag Manager (and who it fits)

Matomo is a self-hostable analytics platform (GPLv3). Matomo Tag Manager is a module inside Matomo. It lets you manage tags, triggers, and variables from a web UI—similar to GTM, but served from your own domain.

This setup makes sense if you:

  • Run a content site, SaaS, or e-commerce store and want tag control without adding another vendor to every request.
  • Care about predictable performance. A first-party container hosted on your VPS avoids “why is tagging slow today?” surprises.
  • Need first-party hosting for governance (policy, client requirements, or simply reducing dependencies).

It’s not magic. You’re operating a server. That means patching, monitoring, and treating it like production.

If that’s not realistic for your team, a hosted tag manager will feel simpler.

Self-host Matomo Tag Manager vs Google Tag Manager

GTM wins on convenience and ecosystem. It’s fast to roll out, and plenty of marketing tooling assumes you have it. The cost is dependency: a critical measurement component must load reliably from a third party.

When you self-host Matomo Tag Manager, the tradeoffs flip:

  • Control: Your container lives under your domain on your VPS. You decide what gets loaded.
  • Privacy posture: You can avoid sending visitor metadata to an external tag platform by default.
  • Ops responsibility: You handle OS patching, container updates, TLS, and backups.

If you mainly need analytics plus a handful of pixels and events, Matomo Tag Manager usually fits the workflow well.

If your stack relies on ad-tech integrations built around GTM-specific templates, confirm those requirements before you commit.

Architecture: what you’re actually deploying

A workable Matomo-on-a-VPS setup typically has four parts:

  • Matomo app (PHP) running behind a web server container (commonly Apache in the official image).
  • Database (typically MariaDB).
  • Reverse proxy on the VPS edge (Nginx or Caddy) to terminate TLS and route traffic.
  • Persistent volumes for Matomo config and uploaded assets, plus database storage.

Tag Manager is enabled inside the Matomo UI as a plugin/feature. Once it’s on, Matomo generates a container JavaScript URL. You embed that URL on your site, and Matomo serves it from your Matomo domain.

If you already run other self-hosted apps on the same VPS, use one reverse proxy stack. Route everything through it.

HostMyCode customers often standardize on Nginx or Traefik to keep multi-app routing predictable.

If you prefer the Traefik approach, the pattern in Traefik With Docker Compose for HTTPS on a VPS translates cleanly.

VPS sizing and prerequisites (keep it boring)

Matomo’s footprint depends on traffic, retention, and how many sites you track. A small VPS can work, but don’t starve the database.

  • Minimum practical VPS: 2 vCPU, 2–4 GB RAM, NVMe storage.
  • Comfortable starting point: 2–4 vCPU, 4–8 GB RAM for multiple sites and longer retention.
  • Disk: plan for growth. Archives and DB storage expand quietly over time.

Software baseline for the host:

  • Ubuntu 24.04 LTS (or Debian 12) on your VPS
  • Docker Engine + Docker Compose plugin
  • Nginx installed on the host (or Caddy) for TLS termination

If you don’t want OS patching and service health checks to become background noise, managed VPS hosting is the straightforward option for keeping a self-hosted Matomo stack stable.

Deploy Matomo with Docker Compose (Tag Manager-ready)

Pick a hostname such as matomo.example.com. Point its DNS A/AAAA record to your VPS first.

If you want a clean DNS runbook, adapt the steps from Set Up Cloudflare Tunnel on a VPS for Private Admin. The DNS pieces are the same even if you don’t use Tunnel.

On the VPS, create a directory:

sudo mkdir -p /opt/matomo
cd /opt/matomo

Create docker-compose.yml:

services:
  db:
    image: mariadb:11
    command: --max-allowed-packet=64M
    environment:
      MARIADB_RANDOM_ROOT_PASSWORD: "yes"
      MARIADB_DATABASE: matomo
      MARIADB_USER: matomo
      MARIADB_PASSWORD: change-me-long
    volumes:
      - db_data:/var/lib/mysql
    restart: unless-stopped

  matomo:
    image: matomo:latest
    depends_on:
      - db
    environment:
      MATOMO_DATABASE_HOST: db
      MATOMO_DATABASE_ADAPTER: mysql
      MATOMO_DATABASE_TABLES_PREFIX: matomo_
      MATOMO_DATABASE_USERNAME: matomo
      MATOMO_DATABASE_PASSWORD: change-me-long
      MATOMO_DATABASE_DBNAME: matomo
    volumes:
      - matomo_data:/var/www/html
    restart: unless-stopped

volumes:
  db_data:
  matomo_data:

Bring it up:

sudo docker compose up -d
sudo docker compose ps

At this point Matomo listens on its internal container port (Apache in the image). Don’t expose the container directly. Publish it through a reverse proxy.

Reverse proxy + HTTPS (Nginx + Let’s Encrypt)

Serving analytics and tag scripts over plain HTTP isn’t workable. Browsers block mixed content, and you’ll leak measurement traffic. Terminate TLS at Nginx on the host, then proxy to the Matomo container.

1) Install Nginx and Certbot (Ubuntu):

sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx

2) Create an Nginx site at /etc/nginx/sites-available/matomo:

server {
  listen 80;
  server_name matomo.example.com;

  location / {
    proxy_pass http://127.0.0.1:8080;
    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;
  }

  client_max_body_size 64m;
}

3) Publish Matomo on localhost port 8080 by adding a ports mapping (edit the compose file):

  matomo:
    image: matomo:latest
    ...
    ports:
      - "127.0.0.1:8080:80"

Apply the change:

cd /opt/matomo
sudo docker compose up -d

Enable the Nginx site and test:

sudo ln -s /etc/nginx/sites-available/matomo /etc/nginx/sites-enabled/matomo
sudo nginx -t
sudo systemctl reload nginx

4) Issue the certificate:

sudo certbot --nginx -d matomo.example.com

Certbot will update the server block for HTTPS automatically. After that, open https://matomo.example.com and complete the Matomo web installer.

Operational note: Matomo must know it’s behind HTTPS. If you see redirect loops or “insecure” warnings, configure trusted proxy headers in Matomo (via UI or config).

Most issues here come from a missing X-Forwarded-Proto.

Enable Matomo Tag Manager and keep the script first-party

After Matomo is installed:

  • Log in as an admin.
  • Go to Marketplace / Plugins (depending on your UI layout).
  • Enable Tag Manager.

Create a container, then copy the container embed code into your website. The practical difference versus GTM is the origin. Your container JS loads from matomo.example.com, not a third-party domain.

If you also want analytics without third-party JS, keep Matomo’s tracker script first-party too. The default Matomo snippet already points to your Matomo domain. Add hosted tag libraries only when you actually need them.

Performance and reliability tips (the stuff you notice later)

Matomo can run smoothly for weeks, then slow down once archiving and reporting load builds up. A few basic habits prevent most of that pain.

  • Run archiving via cron instead of relying on browser-triggered archiving. In Matomo settings, configure the recommended cron job and run it on the host using cron or a systemd timer.
  • Give MariaDB RAM. If the VPS is tight on memory, the database will thrash and the UI will lag.
  • Keep the reverse proxy simple. A single Nginx frontend is easy to debug and easy to renew certs for.

If the same VPS also runs WordPress or other PHP apps and you start seeing timeouts, assume resource contention first.

Disk and IO issues show up early with analytics workloads.

This checklist helps when Matomo’s database grows and storage pressure creeps in: Disk Full on VPS: Find Large Files and Free Space Safely.

Backups: what to copy, how often, and how to test

A Matomo backup has two pieces: the database and the Matomo volume (config + plugins + generated assets). Backing up only one will eventually hurt you.

A reliable VPS-friendly approach:

  • Nightly database dump (compressed).
  • Nightly tar archive of the Matomo volume.
  • Offsite copy (object storage or another server). Same datacenter is not “offsite.”

Example backup script (store as /opt/matomo/backup.sh and run via cron):

#!/usr/bin/env bash
set -euo pipefail

TS=$(date +%F-%H%M)
BACKUP_DIR=/opt/matomo/backups
mkdir -p "$BACKUP_DIR"

cd /opt/matomo

# DB dump
sudo docker compose exec -T db mariadb-dump -u matomo -p'change-me-long' matomo | gzip > "$BACKUP_DIR/matomo-db-$TS.sql.gz"

# Matomo files volume (named volume -> tar from a temporary container)
sudo docker run --rm \
  -v matomo_matomo_data:/data \
  -v "$BACKUP_DIR":/backup \
  alpine sh -c "cd /data && tar -czf /backup/matomo-files-$TS.tar.gz ."

Test restores quarterly. Bring up a scratch VPS, restore the DB and files, then verify you can log in and load a report.

If you can’t restore, you don’t have backups—you have archives.

Updates: minimize risk, avoid surprise breakage

Matomo updates are often straightforward, but you still want a routine. Backup first. Then update containers, and validate tracking and publishing.

On the VPS:

cd /opt/matomo
sudo docker compose pull
sudo docker compose up -d
sudo docker image prune -f

Then check:

  • The Matomo UI loads and shows the expected version.
  • Tracking requests still arrive (Realtime reports or access logs).
  • Your Tag Manager container still publishes without errors.

If you prefer automated container updates, set boundaries. Blind “latest” upgrades can still break things.

A safer pattern is: pin major versions, auto-update minor/patch, and alert on container restarts.

This walkthrough shows one way to do it: Docker Compose Auto-Updates With Watchtower on a VPS.

Security baseline: small steps that block real attacks

Your Matomo login is an admin surface. Once the hostname points at a public IP, expect credential stuffing and generic scans.

  • Use strong admin passwords and enable 2FA if available in your Matomo setup.
  • Keep SSH tight: key-based auth, no password logins, and restrict by IP where possible.
  • Consider CrowdSec for automated IP blocking on common probes and brute force patterns. The deployment pattern in Install CrowdSec on Ubuntu VPS to Block Bruteforce is a practical starting point.

If you serve your tag container from the same Matomo domain, treat that domain like production infrastructure.

If someone gets admin access, they can change what script your pages load.

Where Matomo fits in a real hosting setup

For many teams, separation is the cleanest model. Keep your main web stack (WordPress, app servers, primary databases) on one VPS or cluster. Run analytics/tagging on another.

This reduces blast radius and makes scaling decisions clearer.

If you do consolidate on one box, watch for noisy-neighbor effects. Database IO, backups, and archiving jobs will compete with your primary app.

If you’re already close to the edge, moving Matomo to its own VPS is often cheaper than chasing intermittent slowdowns for months.

HostMyCode’s HostMyCode VPS plans fit Matomo well because analytics databases benefit from consistent CPU and disk performance.

If you’d rather not maintain the stack yourself, managed VPS hosting is the practical step up for a measurement system you depend on every day.

If you’re ready to run Matomo as a first-party analytics and tag stack, start with a VPS sized for steady database IO and straightforward TLS termination. HostMyCode can provision that quickly on HostMyCode VPS, or you can hand off patching and uptime checks to managed VPS hosting so Matomo stays quiet in production.

FAQ

Do I need Matomo to use Matomo Tag Manager?

Yes. Tag Manager runs inside Matomo. Install Matomo first, then enable the Tag Manager feature/module in the UI.

Can I serve the tag container from the same domain as my website?

You typically serve it from your Matomo domain (for example, matomo.example.com). Serving from the exact same apex domain is possible with careful routing, but it complicates your web stack. A dedicated subdomain is simpler and still first-party.

What should I back up for Matomo?

Back up both the database (MariaDB) and the Matomo persistent volume. A DB-only backup won’t include config and plugin assets; a files-only backup won’t include your data.

How do I update safely without breaking tracking?

Back up first, then docker compose pull and docker compose up -d. After updates, verify the UI loads, tracking requests arrive, and your container publishes correctly.

Is Matomo good enough to replace GA + GTM for most sites?

For many sites, yes—especially if your goals are first-party analytics and controlled event tagging. If you depend on a deep ad-tech ecosystem that assumes Google templates, validate those integrations before migrating.

Summary: keep tag control, keep the scripts on your infrastructure

If you want tag-manager flexibility without adding another third party to every page load, running Matomo with Tag Manager is a practical middle ground. You get the familiar workflow—containers, triggers, and variables—while serving scripts from your own domain over HTTPS.

Run it on a VPS you can scale, back it up like a database (because it is), and update on a schedule.

If you want a stable place to host it, start with a HostMyCode VPS and keep the analytics stack isolated from your main production app as you grow.