How to Install Matomo Analytics

Matomo (formerly Piwik) is a full-featured, self-hosted web analytics platform offering deeper functionality than lighter alternatives like Plausible — including heatmaps, session recordings, and detailed visitor tracking, while keeping full data ownership.

Prerequisites

  • Ubuntu 22.04/24.04 VPS with Nginx or Apache, PHP, and MySQL/MariaDB installed
  • A domain name pointing to your VPS

Step 1 — Create a Database

sudo mysql
CREATE DATABASE matomo;
CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'CHANGE_ME_STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 2 — Download Matomo

cd /var/www
sudo wget https://builds.matomo.org/matomo.zip
sudo unzip matomo.zip
sudo rm matomo.zip
sudo chown -R www-data:www-data /var/www/matomo

Step 3 — Configure Nginx

sudo nano /etc/nginx/sites-available/matomo
server {
    listen 80;
    server_name analytics.yourdomain.com;
    root /var/www/matomo;
    index index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
sudo ln -s /etc/nginx/sites-available/matomo /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Step 4 — Complete the Web Installer

http://analytics.yourdomain.com

Follow the installation wizard: system check, database configuration (using credentials from Step 1), and creating your administrator account.

Step 5 — Add Your First Website

During setup, or later from the admin panel, add your website's URL to generate a tracking code.

Step 6 — Add the Tracking Code to Your Website

<script>
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="https://analytics.yourdomain.com/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>

Step 7 — Add HTTPS

sudo certbot --nginx -d analytics.yourdomain.com

Setting Up the Archive Cron Job (Recommended for Performance)

sudo crontab -e -u www-data
5 * * * * /usr/bin/php /var/www/matomo/console core:archive --url=https://analytics.yourdomain.com > /dev/null

Pre-computes report data on a schedule rather than on-demand, significantly improving dashboard load times.

Matomo vs Plausible

FactorMatomoPlausible
Feature depthExtensive (heatmaps, session recording, funnels)Simple, focused core metrics
Resource requirementsHigherLower
Setup complexityMore involved (PHP/MySQL stack)Simpler (single Docker stack)

Common Errors

Installer fails a system requirement check — review the specific PHP extension or configuration flagged and install/adjust accordingly.

Slow dashboard loading — confirm the archive cron job is configured and running.

Continue Reading

Browse more articles in Popular Self-Hosted Applications.

  • matomo, piwik, self hosted analytics, web analytics
  • 0 Uživatelům pomohlo
Byla tato odpověď nápomocná?

Související články

How to Install Nextcloud on a VPS with Docker

Nextcloud is a self-hosted file sync, sharing, and collaboration platform — a...

How to Install GitLab CE on a VPS

GitLab Community Edition is a full-featured, self-hosted DevOps platform — Git repository...

How to Install Ghost CMS on a VPS

Ghost is a modern, fast, purpose-built platform for blogging and newsletters — a lighter,...

How to Set Up a Minecraft Server on a VPS

Running your own Minecraft server gives you full control over mods, plugins, and world settings....

How to Install n8n for Workflow Automation

n8n is a self-hosted workflow automation tool — connecting apps and APIs through a visual...