Self-host guide

How to Self-Host Matomo on a VPS

Run Matomo on Ubuntu 24.04 with Matomo's Docker Compose setup (app, MariaDB, archiving cron), Caddy HTTPS, database dumps and safe updates.

Matomo is a web analytics platform and a self-hosted alternative to Google Analytics, with goals, ecommerce reports, segments and full ownership of the raw data. This guide installs it by hand on Ubuntu 24.04 with the Docker Compose setup that Matomo's own FAQ recommends for production: the Matomo app, a MariaDB database and a cron container that processes reports in the background. Caddy sits in front for HTTPS.

Prefer one click? Deploy Matomo from the VeloxaHost marketplace and skip the manual steps; this guide is for when you want to run every command yourself.

What you need

  • A VeloxaHost server with the Ubuntu 24.04 LTS image. You get root, over SSH or in the browser terminal on the server's page.
  • A subdomain such as analytics.example.com and a dedicated IPv4 address. Websites served over HTTPS can only load the tracking code over HTTPS, and Caddy gets its certificate over ports 80 and 443, which the shared IPv4 address does not offer; it only gives you a block of forwarded ports. A dedicated IPv4 is a paid add-on (the console shows the current price): choose it as "Network access" on the create page, or take one from the IP addresses page and attach it. If none is free in the region, the request is refused.

Matomo sizes servers by traffic. For up to 100,000 pageviews a month it recommends 2 CPUs, 2 GB of RAM and 50 GB of SSD for app and database together. A Veloxa 2 (2 vCPU, 4 GB RAM, 80 GB disk) at $15 a month, billed at $0.03 an hour and capped at the monthly price, covers that. Up to a million pageviews, Matomo asks for 4 CPUs, 8 GB and 250 GB.

Install Matomo

  1. Make the server answer on its dedicated IPv4. Add the address to the interface (check the name with ip addr) and to the network configuration so it survives a reboot. Then create an A record for analytics.example.com pointing at it. IPv6 is not available in US East yet, so skip the AAAA record there.

    ip addr add 198.51.100.5/32 dev eth0
    
  2. Install Docker Engine and the Compose plugin from Docker's apt repository, as in Docker's Ubuntu guide. sudo also works as root.

    # Add Docker's official GPG key:
    sudo apt update
    sudo apt install ca-certificates curl
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
    
    # Add the repository to Apt sources:
    sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
    Types: deb
    URIs: https://download.docker.com/linux/ubuntu
    Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
    Components: stable
    Architectures: $(dpkg --print-architecture)
    Signed-By: /etc/apt/keyrings/docker.asc
    EOF
    
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    sudo docker run hello-world
    
  3. Create a directory named matomo and, inside it, docker-compose.yml. This is the file from Matomo's Docker FAQ with three changes: Matomo is published on 127.0.0.1 only, because Caddy runs on the same server; the database image is mariadb:lts with MARIADB_AUTO_UPGRADE, as in the example in Matomo's Docker repository, so a pull never jumps to an unplanned major version; and both passwords are yours to choose.

    services:
      db:
        image: mariadb:lts
        container_name: matomo-db
        restart: unless-stopped
        environment:
          MYSQL_ROOT_PASSWORD: your-root-password
          MYSQL_DATABASE: matomo
          MYSQL_USER: matomo
          MYSQL_PASSWORD: your-matomo-password
          MARIADB_AUTO_UPGRADE: "1"
        volumes:
          - matomo-db-data:/var/lib/mysql
    
      matomo:
        image: matomo:latest
        container_name: matomo-app
        restart: unless-stopped
        ports:
          - "127.0.0.1:8080:80"
        environment:
          MATOMO_DATABASE_HOST: db
          MATOMO_DATABASE_USERNAME: matomo
          MATOMO_DATABASE_PASSWORD: your-matomo-password
          MATOMO_DATABASE_DBNAME: matomo
        volumes:
          - matomo-app-data:/var/www/html
        depends_on:
          - db
    
      cron:
        image: matomo:latest
        container_name: matomo-cron
        restart: unless-stopped
        volumes:
          - matomo-app-data:/var/www/html
        entrypoint: >
          /bin/sh -c "while true; do
          php /var/www/html/console core:archive;
          sleep 300;
          done"
        depends_on:
          - db
    
    volumes:
      matomo-db-data:
      matomo-app-data:
    

    The cron container runs core:archive every five minutes. The database publishes no port, so only Matomo can reach it.

  4. Start the stack and check that all three containers run.

    cd matomo
    sudo docker compose up -d
    sudo docker ps -a
    
  5. Install Caddy from its apt repository, as in Caddy's install docs.

    sudo apt install --yes debian-keyring debian-archive-keyring apt-transport-https curl
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
    sudo chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg
    sudo chmod o+r /etc/apt/sources.list.d/caddy-stable.list
    sudo apt update
    sudo apt install caddy
    
  6. Replace /etc/caddy/Caddyfile with this, then reload Caddy. These three lines are ours; Matomo's docs do not include a Caddy example.

    analytics.example.com {
        reverse_proxy 127.0.0.1:8080
    }
    
    sudo systemctl reload caddy
    

First login

Open https://analytics.example.com and follow the setup wizard. At the database step, enter the values from the compose file: database server db, login matomo, your Matomo password and database name matomo. Then create the superuser and your first website, and copy the tracking code into your site.

Tell Matomo it runs behind a proxy, as its proxy FAQ describes. The config file lives in the app volume; on the host, Docker keeps it under /var/lib/docker/volumes/matomo_matomo-app-data/_data/config/config.ini.php (the path follows from the matomo directory name). Under [General], add:

assume_secure_protocol = 1
force_ssl = 1
proxy_client_headers[] = HTTP_X_FORWARDED_FOR

Without the last line, every visit is recorded with the proxy's address instead of the visitor's.

Finally, since the cron container processes reports, go to Administration, System, General settings and turn off Archive reports when viewed from the browser.

Secure it

In the console, go to Firewalls, New Firewall, Add Rule. Allow TCP 80 and 443 from 0.0.0.0/0 and TCP 22 only from YOUR.IP/32, then attach the firewall on the server's page. Until one is attached, all traffic is allowed. Ports published by Docker bypass ufw, so rely on the VeloxaHost firewall; the compose file keeps 8080 on localhost.

From Matomo's security FAQ:

  • Turn on two-factor authentication under Administration, Personal, Security, and keep the recovery codes safe. A superuser can then require it for everyone.
  • Always use HTTPS; force_ssl = 1 above redirects plain HTTP.
  • Install the SecurityInfo plugin and work through its findings.
  • Matomo notes that its Docker images are not part of its own security assessments, so pull fresh images regularly.

For scheduled email reports, set your provider's SMTP server under Administration, System, General settings. Outbound TCP port 25 is blocked by default, so use port 587 or 465.

Back it up

Matomo's backup FAQ names three things: the database, config/config.ini.php and any plugins you added from the Marketplace. The dump flags below are from that FAQ. Running them inside the database container with mariadb-dump and the container's own password variable is our adaptation:

cd matomo
sudo docker compose exec -T db sh -c 'mariadb-dump --extended-insert --no-autocommit --quick --single-transaction matomo -umatomo -p"$MYSQL_PASSWORD"' > matomo_backup_database.sql
sudo tar czf matomo-files.tar.gz -C /var/lib/docker/volumes/matomo_matomo-app-data/_data config plugins

Restoring means a fresh install, the database imported, and the config file and plugins copied back. Matomo cannot restore part of the data into a running database.

On VeloxaHost, snapshots are instant and free (5 on Starter, 30 on Pay as you go): server page, Snapshots, name, Create. Restoring overwrites the current state. Automatic snapshots run every hour, 6 hours, 12 hours, daily or weekly, kept for 1, 3, 7, 14 or 30 days. The Backups page creates, downloads and restores server backups (as a new server), on a schedule of every 6 hours, 12 hours, daily or weekly, keeping 1 to 10. Download one now and then for an off-site copy.

Update it

Matomo's Docker FAQ says to pull the new image and recreate the containers. That updates PHP and the system packages, but not always Matomo itself. The image's start script copies Matomo's files into /var/www/html only when the volume is empty, so a volume from an earlier install keeps its old code.

So update in two parts. Take a snapshot and a database dump first. Then update Matomo with the one-click update in Administration when it offers a new version; the files in the volume belong to www-data, so the updater can write them. After a large update, run the database step from the command line, which Matomo recommends for busy sites:

sudo docker compose exec -u www-data matomo php /var/www/html/console core:update

Then refresh the images and recreate the containers. Matomo's FAQ pulls only the matomo service; pulling everything also refreshes MariaDB, which the FAQ advises keeping current. The cron container shares the Matomo image:

sudo docker compose pull
sudo docker compose up -d

The newest Matomo release was 5.14.1 when checked. Afterwards, check Administration, Diagnostics, System check.

Troubleshooting

The installer appears again after a restart. Matomo cannot find its config, usually because the matomo-app-data volume was removed. Restore it from a backup or snapshot.

"Matomo couldn't write to some directories". The www-data user cannot write to the volume. Fix ownership on the host side rather than inside the container, where changes do not persist.

Reports stay empty. Check the archiving loop with sudo docker compose logs cron.

Every visitor has the same IP address. The proxy_client_headers[] line is missing or still commented out.

FAQ

What license is Matomo under?

Matomo On-Premise is free software under the GPL v3 or later. Matomo also sells a hosted cloud service and paid premium plugins.

Why does Matomo need a dedicated IPv4 address on VeloxaHost?

Websites served over HTTPS can only load the tracking script over HTTPS. Caddy needs ports 80 and 443 to get and serve a certificate, and the shared IPv4 address only offers a block of forwarded ports.

Do I still need cron for report archiving?

Yes, but the cron container in the compose file does it, running core:archive every five minutes. Matomo recommends turning off browser-triggered archiving once it runs, so reports are not processed during page views.

Where does Matomo keep its data?

In two Docker volumes. matomo-db-data holds the MariaDB database with every visit and report. matomo-app-data holds Matomo's files, including config/config.ini.php and installed plugins. The backup above takes what matters from each: a database dump, and the config and plugins.

Which VeloxaHost size fits Matomo?

Up to 100,000 pageviews a month, a Veloxa 2 (2 vCPU, 4 GB RAM, 80 GB disk) at $15 a month, billed at $0.03 an hour and capped at the monthly price. Up to a million, Matomo asks for 4 CPUs, 8 GB of RAM and 250 GB of disk; a Veloxa 8 (8 vCPU, 16 GB RAM, 320 GB disk) at $60 a month, billed at $0.09 an hour and capped at the monthly price, is the first size that meets all three.

Commands and settings checked on 2026-10-19 against the official documentation: matomo.org, github.com, docs.docker.com, caddyserver.com. Software changes; if a step no longer matches, the vendor's docs win.

Ready to deploy?

Start a free trial, or compare plans to match your team's scale.