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
| Factor | Matomo | Plausible |
|---|---|---|
| Feature depth | Extensive (heatmaps, session recording, funnels) | Simple, focused core metrics |
| Resource requirements | Higher | Lower |
| Setup complexity | More 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.
Related Articles
- How to Install Plausible Analytics (Privacy-Friendly Web Analytics)
- How to Install PHP on Ubuntu & Debian
- How to Install and Secure MySQL 8 on Ubuntu & Debian
