How to self-host website analytics with Matomo and Docker

How to self-host website analytics with Matomo and Docker

Self-host website analytics with Matomo and Docker by running Matomo, MariaDB, and an archive cron service in separate containers on your own server. This setup keeps analytics data in your own database, gives you control over retention and access, and lets you track visits, pageviews, referrers, devices, goals, and conversions without relying on a cloud analytics provider.

The setup starts with a VPS or Linux server that has Docker Compose installed. After preparing the server, create the Docker Compose file, start the Matomo containers, complete the browser-based setup wizard, and add the generated tracking code to your website.

For production use, configure HTTPS, backups, container updates, and auto-archiving. These steps keep the Matomo dashboard secure, preserve analytics data, and help reports load faster as traffic grows.

What do you need before installing Matomo with Docker?

Before installing Matomo with Docker, set up your private server, domain, and access details you need to run the analytics platform reliably.

Use this checklist:

  • A VPS or Linux server with Docker and Docker Compose installed.
  • Root or sudo access to run Docker commands.
  • A domain or subdomain for Matomo, such as analytics.example.com.
  • DNS records pointing the domain or subdomain to your VPS IP address.
  • Open ports for web access, usually 80, 443, or a temporary setup port like 8080.
  • A strong database password for MariaDB or MySQL.
  • Enough storage for analytics data, especially if you track high-traffic websites or keep long data retention periods.
  • A backup plan for the Matomo database and application files.
  • Access to the website where you will add the Matomo tracking code.

Once these are ready, you can create the Docker Compose file, start the Matomo containers, and complete the setup wizard in your browser.

How to install Matomo with Docker Compose

Docker Compose is the recommended way to install Matomo for a self-hosted analytics setup, as Matomo requires more than one container in production. The setup below runs Matomo, a MariaDB database, and a cron container for automatic report archiving.

First, create a new directory for your Matomo deployment:

mkdir matomo-docker
cd matomo-docker

Next, create a docker-compose.yml file:

nano docker-compose.yml

Add the following configuration:

services:
db:
image: mariadb:11
container_name: matomo-db
command: --max-allowed-packet=64MB
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: change_this_root_password
MYSQL_DATABASE: matomo
MYSQL_USER: matomo
MYSQL_PASSWORD: change_this_matomo_password
volumes:
- matomo_db:/var/lib/mysql
matomo:
image: matomo:5-apache
container_name: matomo-app
restart: unless-stopped
depends_on:
- db
ports:
- "8080:80"
environment:
MATOMO_DATABASE_HOST: db
MATOMO_DATABASE_ADAPTER: mysql
MATOMO_DATABASE_TABLES_PREFIX: matomo_
MATOMO_DATABASE_USERNAME: matomo
MATOMO_DATABASE_PASSWORD: change_this_matomo_password
MATOMO_DATABASE_DBNAME: matomo
volumes:
- matomo_app:/var/www/html
cron:
image: matomo:5-apache
container_name: matomo-cron
restart: unless-stopped
depends_on:
- db
- matomo
volumes:
- matomo_app:/var/www/html
entrypoint: /bin/sh
command: -c "while true; do php /var/www/html/console core:archive --url=http://matomo-app/; sleep 300; done"
volumes:
matomo_db:
matomo_app:

Replace change_this_root_password and change_this_matomo_password with strong passwords before starting the containers. The DB service stores Matomo analytics data, the Matomo service runs the web application, and the cron service processes analytics reports in the background.

Start Matomo with Docker Compose:

docker compose up -d

Check whether the containers are running:

docker compose ps

You should see three running services: matomo-db, matomo-app, and matomo-cron.

Open Matomo in your browser using your server IP address and port 8080:

http://your-server-ip:8080

During the setup wizard, enter db as the database server, matomo as the database login, the value of MYSQL_PASSWORD as the password, matomo as the database name, and matomo_ as the table prefix.

After the database connection is established, create your Matomo superuser and add the website you want to track. Matomo will then generate a JavaScript tracking code for that website.

Copy the tracking code and place it before the closing tag on your website. Once the code is added, Matomo starts collecting visits, page views, referrers, devices, locations, goals, and other website analytics data in your self-hosted dashboard.

How to deploy Matomo with Hostinger’s Docker template

Hostinger’s Docker catalog lets you deploy Matomo without manually creating containers, configuring Docker Compose, or installing the analytics application from scratch. The template launches a preconfigured Matomo instance on a VPS, while you complete the browser-based setup, connect your website, and configure production settings afterward.

To deploy Matomo with Hostinger’s Docker template:

  1. Go to Hostinger’s Matomo Docker template page.
  2. Choose a VPS plan based on your website traffic and data retention needs.
  3. Complete the checkout and open hPanel.
  4. Select the Matomo template during VPS setup.
  5. Wait until Hostinger finishes provisioning the VPS and deploying the application.
  6. Open the Matomo URL or server IP address shown in hPanel.
  7. Complete the Matomo setup wizard.
  8. Add your website and copy the tracking code.
  9. Insert the tracking code before the closing tag on your website.

After deployment, open the Docker manager in hPanel to manage the Matomo containers, view container logs, and apply one-click updates. Hostinger’s Docker VPS plans include Docker manager, quick access to container logs, one-click updates, automatic weekly backups, NVMe storage, and 1 Gbps network speed, which helps simplify day-to-day Matomo maintenance.

The Docker template handles the initial application deployment, but Matomo still needs website-specific configuration. Add your first website in the setup wizard, copy the generated JavaScript tracking code, and place it on every page you want to track. Once the tracking code is active, Matomo starts recording visits, pageviews, referrers, devices, locations, goals, and other analytics data inside your self-hosted dashboard.

For production use, connect Matomo to a domain or subdomain such as analytics.example.com, enable HTTPS, review your privacy settings, and keep backups enabled. These steps make your self-hosted analytics setup easier to access, safer to maintain, and better suited for long-term website tracking.

How to configure Matomo for production

A working Matomo container is sufficient for testing, but production analytics requires additional configuration for performance, security, and data protection. Before tracking real website visitors, configure auto-archiving, HTTPS, backups, and updates.

1. Enable auto-archiving with cron

By default, Matomo processes analytics reports when users open the dashboard. This works for small test sites, but it slows down Matomo as traffic and stored data grow. Auto-archiving moves report processing to a scheduled background task.

The Docker Compose setup above already includes a cron service that runs Matomo’s archive command every five minutes:

php /var/www/html/console core:archive --url=http://matomo-app/

After confirming that the cron container is running, disable browser-triggered archiving in Matomo:

  1. Log in to your Matomo dashboard.
  2. Go to AdministrationSystemGeneral settings.
  3. Find the Archiving settings section.
  4. Set Archive reports when viewed from the browser to No.
  5. Save the changes.

This setup lets the cron container process reports in the background while the Matomo dashboard loads already prepared analytics data.

2. Add HTTPS with a reverse proxy

Matomo should use HTTPS in production because it handles login sessions, tracking requests, and website analytics data. The safest setup is to point a domain or subdomain, such as analytics.example.com, to your VPS and place Matomo behind a reverse proxy.

You can use NGINX, Caddy, Traefik, or another reverse proxy to:

  • Route traffic from your domain to the Matomo container.
  • Issue and renew an SSL certificate.
  • Serve the Matomo dashboard over HTTPS.
  • Keep port 8080 closed from direct public access.

For example, if you use NGINX Proxy Manager, create a proxy host that forwards analytics.example.com to the Matomo container or server IP on port 8080, then enable SSL with Let’s Encrypt.

After enabling HTTPS, update Matomo’s trusted host settings if the dashboard shows a trusted host warning. Open the Matomo configuration file inside the application volume and add your analytics domain under trusted_hosts[].

docker exec -it matomo-app nano /var/www/html/config/config.ini.php

Add or confirm the following value:

[General]
trusted_hosts[] = "analytics.example.com"

Replace analytics.example.com with the domain or subdomain you use for Matomo.

3. Back up Matomo files and database

Matomo stores production data in two places: the MariaDB database and the Matomo application files. The database contains visits, reports, users, goals, and website settings. The application volume stores Matomo configuration, plugins, and generated files.

Create database backups regularly with mysqldump:

docker exec matomo-db mysqldump -u matomo -p matomo > matomo-database-backup.sql

When prompted, enter the same password you set as MYSQL_PASSWORD in your Docker Compose file.

Back up the Matomo application volume by creating an archive from the running container:

docker run --rm
-v matomo-docker_matomo_app:/volume
-v $(pwd):/backup
alpine
tar czf /backup/matomo-files-backup.tar.gz -C /volume .

The exact volume name may differ if your project folder has a different name. Run this command to list available Docker volumes:

docker volume ls

Keep backups outside the VPS as well. A local backup protects against failed updates, but an external backup protects against server-level data loss.

4. Update Matomo containers safely

Container updates keep Matomo secure and compatible with the latest features. Before updating, create a fresh database and file backup.

Then pull the latest images and recreate the containers:

docker compose pull
docker compose up -d

Check the container status after the update:

docker compose ps

Then open the Matomo dashboard and complete any database upgrade prompts if Matomo displays them. Keep the named Docker volumes in your Compose file unchanged, because they preserve your database and Matomo files when containers are recreated.

5. Review privacy and data retention settings

Matomo gives you control over how analytics data is collected and stored. For a privacy-friendly setup, review the privacy settings before adding Matomo tracking to a live website.

In the Matomo dashboard, go to AdministrationPrivacy and configure:

  • IP address anonymization.
  • Do Not Track preference support.
  • Cookie consent or cookieless tracking.
  • Data retention periods for raw visitor logs.
  • User permissions for team members.
  • Opt-out settings if your website needs them.

Use the settings that match your website’s legal requirements and analytics needs. For example, a personal blog may only need anonymized traffic reports, while an ecommerce site may need goals, conversions, and longer retention for sales analysis.

After these production settings are complete, Matomo is ready to collect website analytics from your own server with stronger control over privacy, storage, and maintenance.

When should you self-host Matomo instead of using cloud analytics?

Self-hosting Matomo is the better option when you want to control where analytics data is stored, how long it is retained, and who can access it. Cloud analytics tools are easier to start with, but they send website data to a third-party platform and limit how much control you have over the analytics infrastructure.

Self-host Matomo with Docker if you want to:

  • Keep website analytics data on your own VPS instead of a third-party analytics platform.
  • Use privacy-friendly tracking for websites that need stricter data control.
  • Manage your own data retention, backups, plugins, and access permissions.
  • Track visits, pageviews, referrers, devices, locations, goals, and conversions from a self-hosted dashboard.
  • Avoid depending on a cloud analytics provider for core website reporting.
  • Use Docker to make deployment, updates, and migration easier.

Cloud analytics may be a better fit if you do not want to maintain a server, configure backups, manage updates, or monitor container health. A hosted platform removes much of the infrastructure work, but it also gives you less control over data storage and server-level configuration.

For most privacy-focused websites, Matomo with Docker offers a stronger long-term setup. Docker keeps the analytics application portable, Matomo keeps reporting under your control, and a VPS gives you ownership over the infrastructure that stores visitor data. After deployment, the most important next steps are enabling HTTPS, confirming auto-archiving, keeping backups active, and adding the tracking code to every page you want to measure.

Author
The author

Domantas Pocius

Domantas is a Content SEO Specialist who focuses on researching, writing, and optimizing content for organic growth. He explores content opportunities through keyword, market, and audience research to create search-driven content that matches user intent. Domantas also manages content workflows and timelines, ensuring SEO content initiatives are delivered accurately and on schedule. Follow him on LinkedIn.

What our customers say