Guide: Self-Host Matomo Analytics on Your Server

Introduction

Want detailed website analytics without compromising user privacy? Matomo (formerly Piwik) is a powerful open-source alternative to Google Analytics that you can self-host. In this guide, we’ll show you how to set up Matomo on your own server, step by step.

Who is this for?

  • Privacy-focused website owners
  • Bloggers and small businesses
  • Self-hosters comfortable with basic server setup

What you’ll get:

  • A working Matomo analytics instance
  • Tracking on your websites without third-party scripts
  • GDPR-compliant analytics with full data ownership

Why Choose Matomo?

FeatureMatomo
Privacy100% data ownership, GDPR compliant
FunctionalityReal-time data, heatmaps, goals, ecommerce
HostingSelf-hosted or cloud (we focus on self)
IntegrationEasy integration with WordPress and others
Open SourceYes, GPLv3 licensed

Matomo is ideal if you care about ethical analytics—keeping your visitors’ data out of Google’s hands while still gaining rich insights.

Requirements

  • Linux server (Ubuntu 22.04+ recommended)
  • Root or sudo access
  • Web server (Nginx or Apache)
  • PHP 8.1+ with extensions
  • MariaDB or MySQL
  • Optional: HTTPS with Let’s Encrypt

Step-by-Step Installation

1. Install Required Packages

sudo apt update
sudo apt install nginx mariadb-server php php-fpm php-mysql php-cli php-curl php-gd php-xml php-mbstring php-zip unzip wget -y

2. Create Database

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

3. Download and Install Matomo

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

4. Configure Web Server

Example Nginx config:

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:/var/run/php/php8.1-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}
sudo ln -s /etc/nginx/sites-available/matomo /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

5. Finish Installation via Web UI

Visit: http://analytics.yourdomain.com

  • Follow the installation wizard
  • Provide DB credentials
  • Create admin user
  • Get your tracking code

Tip: Secure your site with HTTPS (e.g., Certbot).

Adding Tracking to Your Site

Copy the JavaScript snippet from Matomo and add it to your site’s <head> section. If you’re using WordPress, plugins like Matomo for WordPress or Insert Headers and Footers make this easier.

Optional settings:

  • Enable Do Not Track compliance
  • Set cookie expiration
  • Anonymize IPs for extra privacy

Advanced Configurations (Optional)

Enable Cron for Reports

sudo crontab -e

Add:

5 * * * * /usr/bin/php /var/www/matomo/console core:archive --url=https://analytics.yourdomain.com >> /var/log/matomo-archive.log

Enable GeoIP2

  • Download GeoLite2 DB from MaxMind
  • Place in /var/www/matomo/misc
  • Enable via Matomo settings

Email Reports

  • Configure SMTP in Matomo Settings
  • Set up scheduled email reports

FAQs

Q: Can Matomo replace Google Analytics completely?
A: Yes, for most use cases—especially traffic and behavior analysis.

Q: Is Matomo GDPR compliant?
A: Yes, especially when self-hosted. You control all data.

Q: Can I track multiple websites?
A: Yes. Matomo supports multi-site tracking by default.

Final Thoughts

Self-hosting Matomo is a great step toward taking control of your website’s data. While it takes a bit more setup than cloud analytics, the privacy benefits and ownership make it worthwhile—especially for ethical sites.

Analytics should serve you, not a third-party ad network.

Support SelfhostHero: If you found this helpful, consider linking to our site or using affiliate links to fund further content. Thank you 🙌