Matomo is an open-source web analytics platform that gives you detailed traffic reports without sending visitor data to a third party. Instead of embedding a script that reports to an external service, you host the tracker and its database yourself. This guide walks through a Docker Compose deployment with MariaDB, explains the initial setup, and covers privacy settings, backups, and monitoring for a small to medium site.

Why Choose Self-Hosted Analytics

Hosted analytics tools are easy to install but they collect data on your behalf, often with retention limits and tracking features you may not want. Matomo runs on your infrastructure, so you decide what is collected, how long it is kept, and who can see reports. For sites subject to privacy regulations, self-hosting removes the question of whether visitor data crosses borders. It also avoids the sampling and data limits that free hosted tiers impose.

Prerequisites

Plan for at least 2 GB of RAM and a few gigabytes of disk for the database, depending on traffic. You need Docker, Docker Compose, a domain pointing at your server, and a reverse proxy that terminates TLS. If you have not deployed a container behind HTTPS before, the Caddy reverse proxy guide is a good starting point. Basic container concepts are covered in the Docker basics guide.

Docker Compose Deployment

Create /opt/matomo and save the following stack as docker-compose.yml. It runs Matomo with MariaDB, keeps both databases on a named volume, and publishes only the web port on localhost for the reverse proxy.

services:
  db:
    image: mariadb:11.4
    container_name: matomo-db
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MARIADB_DATABASE: matomo
      MARIADB_USER: matomo
      MARIADB_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 30s
      timeout: 10s
      retries: 5

  matomo:
    image: matomo:5.2
    container_name: matomo
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      MATOMO_DATABASE_HOST: db
      MATOMO_DATABASE_ADMIN_USER: root
      MATOMO_DATABASE_ADMIN_PASSWORD: ${DB_ROOT_PASSWORD}
      MATOMO_DATABASE_TABLES_PREFIX: matomo_
      MATOMO_DATABASE_USERNAME: matomo
      MATOMO_DATABASE_PASSWORD: ${DB_PASSWORD}
      MATOMO_DATABASE_DBNAME: matomo
    volumes:
      - ./config:/var/www/html/config
      - ./plugins:/var/www/html/plugins
    ports:
      - "127.0.0.1:8080:80"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/"]
      interval: 30s
      timeout: 5s
      retries: 3

volumes:
  db:

Create a .env file with two distinct long passwords:

DB_ROOT_PASSWORD=replace-with-a-long-random-string
DB_PASSWORD=replace-with-a-different-long-random-string

Start the stack with docker compose up -d and wait for both containers to report healthy. Open https://analytics.example.com through your reverse proxy and follow the web installer. Enter the database credentials from .env when prompted, create an admin account with a strong password, and complete the setup.

Matomo can also run behind a local reverse proxy without exposing the database port.

Raw data and aggregated reports are stored separately. Aggregation turns raw visits into the numbers you see in dashboards, and running it on a schedule keeps page views fast. If you enable the option to archive reports on demand, disable it again once cron is working; otherwise every page load can trigger expensive SQL queries.

Privacy and Configuration

Once installed, go to Administration and enable the privacy features that matter for your jurisdiction. IP anonymisation should be on by default; it masks the last bytes of visitor addresses before storage. Set a data retention policy so raw visitor logs are deleted after a defined period, and disable any features you do not use. Matomo can honour Do Not Track headers and integrate with consent managers; configure these according to the consent rules on your site.

Add the tracking code to your site from Administration, Tracking Code. Use the asynchronous snippet and consider loading it only after visitors consent. If your site uses a strict Content Security Policy, allow the analytics domain explicitly. Keep the Matomo admin URL private and protect it with an extra layer of authentication at the reverse proxy if possible.

Backups

Two things must be backed up: the MariaDB volume and the ./config directory, which holds config.ini.php with database credentials. A backup of only the database is useless without the config file. Stop the stack, dump the database with docker compose exec db mariadb-dump -uroot -p"$DB_ROOT_PASSWORD" matomo, and archive both locations. The Docker volume backup guide describes a repeatable pattern, while Restic can encrypt and ship the archives offsite. Test a restore on a separate stack before you rely on it.

Monitoring and Upgrades

Matomo’s cron-based archiving keeps report generation fast on busy sites. Add a host cron entry that runs console core:archive every five minutes inside the container. Watch the database volume with a disk usage alert and add an Uptime Kuma check against the public URL. When upgrading, pin a new image tag, back up first, and read the release notes for required migrations.

Keep an eye on archive processing time; if reports lag behind, increase the cron frequency or add memory rather than deleting history. MariaDB indexes grow with traffic, so run OPTIMIZE TABLE occasionally on a quiet maintenance window if queries slow down.

Common Mistakes

The most frequent error is losing config.ini.php during an upgrade. Another is pointing the tracker at a database user without the right privileges. Skipping IP anonymisation creates unnecessary privacy risk, and exposing the admin login without a reverse proxy invites brute-force attempts.

FAQ

How much traffic can a small Matomo instance handle? With 2 GB of RAM and a few gigabytes of disk, a small personal or business site is comfortable. Enable cron archiving as traffic grows.

Can I import data from another analytics tool? Yes. Matomo offers importers for several platforms and a Log Analytics feature for server logs.

Does Matomo use cookies? By default it can set a visitor ID cookie. You can configure cookieless tracking if your consent policy requires it.

Where are reports stored? In the MariaDB database. That is why the database volume and the config directory must be backed up together.

Can I track multiple sites? Yes. Matomo supports multiple websites from one installation, each with its own tracking code and report set.

What if I forget the admin password? You can reset it with Matomo’s console command inside the container, provided you still have the database credentials from .env. Keep those credentials in a password manager so this recovery path remains available.

Self-hosted Matomo gives you useful analytics without giving away visitor data. Deploy it behind HTTPS, configure privacy defaults, and keep a tested backup of both the database and configuration.