Skip to content

How to Set Up Matomo on a Linux Server – Self-Host Privacy-Friendly Web Analytics

Set up Matomo as a One-Click App or with Docker Compose on your VPS and analyze visits to your websites without sharing data with third-party providers.

1 December 202615 min read1 Views0 helpful

Introduction

Matomo (formerly Piwik) is web analytics software that you host yourself. You can see how many visitors come to your website, which pages they arrive on, where they come from, and which goals they complete. Unlike Google Analytics, all data stays on your own server. Matomo consists of a PHP application and a MariaDB or MySQL database.

In this guide, we’ll show you two ways to set it up: the easy way as a One-Click App, which gets Matomo running with HTTPS and a ready-to-use admin account in just a few minutes, and a manual installation with Docker Compose and an nginx reverse proxy. After that, you’ll learn how to add the tracking code, process reports with cron, and use Matomo’s privacy settings.

When it makes sense to run Matomo on a VPS

Hosting your own Matomo is worthwhile if:

  • You want visitor data to stay with you instead of being transferred to an analytics provider.
  • You want to analyze multiple websites or stores in one place without paying separately for each website.
  • You need the raw data, for example, for custom analyses, goals, e-commerce reports, or segments.
  • You want to set your own privacy settings, such as anonymizing IP addresses or tracking without cookies.

Matomo may not be the best fit if you only need a simple overview of page views and don’t want to maintain a database. In that case, a simpler tool like Plausible may be enough.

Matomo or Plausible?

Both are available as One-Click Apps, but they focus on different things:

MatomoPlausible
ScopeFull web analytics with goals, e-commerce, segments, and heatmap pluginsSimple overview with the most important metrics
InterfaceMany reports and settingsOne dashboard on a single page
DatabaseMariaDBPostgreSQL and ClickHouse
CookiesCan be used with or without cookiesNo cookies
MaintenanceReport archiving and Matomo updatesLittle maintenance

Matomo is the better choice if you need detailed reports, goals, or store analytics. If you only want to see how many visitors you get and which pages are popular, see our separate guide to Setting Up Plausible Analytics on a Linux Server.

Easy option: Matomo as a One-Click App

With your VPS’s One-Click Apps, Matomo will be available at its own HTTPS address in just a few minutes. The app sets up the database, admin account, and first website for you. You don’t need to go through Matomo’s setup wizard, and it’s never accessible to outside visitors.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See VPS: One-Click Apps for instructions.
  • At least 1 GB of RAM, 1 vCPU core, and 5 GB of storage for the app. 2 GB of RAM, 2 vCPU cores, and 50 GB of storage are recommended. According to Matomo, that’s enough for around 100,000 page views per month. The database grows with each visit recorded.
  • An address for Matomo: either a free subdomain on zap.cloud or your own domain, such as analytics.example.com.

Install

  1. Open your VPS in the ZapX dashboard and switch to the One-Click Apps tab.
  2. Search for “Matomo” in the App catalog and click Install app next to Matomo.
  3. Enter a name under App name and leave Use a custom subdomain or zap.cloud enabled. Choose the address where Matomo should be available.
  4. All fields under App configuration are optional. The app generates the username and passwords automatically. It’s a good idea to customize these three values right away:
    • MATOMO_SITE_URL: The address of your first website, such as https://www.example.com. If you leave it blank, the app creates a placeholder website at https://example.com.
    • MATOMO_ADMIN_EMAIL: The email address for the admin account. The default is admin@example.com.
    • MATOMO_TIMEZONE: The time zone for your first website. The default is Europe/Berlin.
  5. Click Queue installation.

After two to three minutes, the app will show as Online. Matomo is already set up: on its first start, the app completed the setup wizard before the address became accessible. Click the app card’s Access link to open the Matomo login page.

Info: These fields only apply during the initial installation

The app reads MATOMO_SITE_URL, MATOMO_ADMIN_EMAIL, and MATOMO_TIMEZONE only on its first start. Changing them later under App environment won’t change anything in Matomo. Update the website, time zone, and email address directly in Matomo instead.

Info: Use a domain with HTTPS

The tracking code loads the matomo.js script from your Matomo address. If your website uses HTTPS, Matomo must also be available over HTTPS, or the browser will block the script. So leave the domain option enabled.

First login: Find your credentials

A Login notice on the app card indicates that the credentials were generated during installation. You can find them in the app settings (gear icon) under App environment > Automatically generated values:

  • Username: The SERVICE_USER_MATOMO field. For the One-Click App, this is zapx.
  • Password: The SERVICE_PASSWORD_MATOMO field.

Click the eye icon to show the values or the copy icon to copy them.

Log in on the login page with your username and password. This account has Superuser permissions, which means full access to all websites and settings. Until visits have been recorded, Matomo displays the Choose your tracking method page after login, with options for adding the tracking code.

Info: Change your password and email address

Enter your own password and real email address by clicking the gear icon in the top right and going to Personal > Security or Settings. If you didn’t enter an email address during installation, it will still show admin@example.com. The value in the app environment no longer applies after that. Matomo displays its interface in your browser's language; this guide uses the English menu names. You can change the language under Personal > Settings. The other values under Automatically generated values are database passwords. Don’t change them.

Add your website

The app creates a first website with ID 1 during installation. Its name and address come from MATOMO_SITE_URL. If you left the field blank, the website is named https://example.com. Check the website and enter your actual details if needed:

  1. Click the gear icon in the top right and select Websites > Manage on the left.
  2. Click the pencil icon next to the first website and enter a name and address for your website, such as https://www.example.com. Enter other addresses for the same website (for example, without www) on separate lines.
  3. Check Time zone and Currency (the default is US dollars), and enable Ecommerce if you want to analyze a store. Click Save.

Add more websites on the same page using Add a new measurable. Each website gets its own number (Site ID) and tracking code. See “Add the tracking code to your website” below for instructions.

What the One-Click App includes—and what it doesn’t

  • Set up for you: A small setup container runs Matomo’s setup wizard on the first start, creates the admin account and first website, then exits. On later restarts, it only checks the configuration. Matomo isn’t accessible at your address until setup is complete, so no one can access the wizard beforehand.
  • Two permanent containers: Matomo with Apache and PHP, and a MariaDB database. The database is only accessible internally; only the app’s domain is exposed externally.
  • Actual visitor IP addresses: The app reads visitors’ IP addresses from the proxy header. Without this setting, Matomo would store the same internal address for every visit.
  • IP anonymization and Do Not Track enabled by default: Matomo truncates each IP address by two bytes and respects the browser’s Do Not Track setting. See “Privacy settings” for more information.
  • No email delivery: Without your own mail server, Matomo won’t send emails, including scheduled reports or password reset emails. Add an SMTP server under System > General settings > Email server settings.
  • No cron-based archiving: Reports are generated when you open them in a browser. That’s fine for small websites, but if you get more visitors, set up a cron job as described in “Archive reports with cron.”
  • Country detection uses browser language only: No geolocation database is set up by default. See “Limitations” for how to enable one.

Updates and backups

  • Update Matomo: Matomo’s program files are stored in the matomo-app volume. Matomo notifies you of new versions at the top of the interface with New Update. Click it to open the built-in updater, which downloads the new version and updates the database. Create a backup first. Before upgrading to a new major version (for example, from 5 to 6), read the version notes on matomo.org.
  • Update the app: In the app settings (gear icon) > App update, click Check for updates to see if a new app version is available, then install it with Apply update. This updates the web server, PHP, and database image. The Matomo version in the volume remains unchanged.
  • Create a backup: A VPS backup from the Backups tab includes the matomo-db volume (all visit and report data) and the matomo-app volume (program files, configuration, and plugins). Both volumes are needed.
  • Uninstall: Under App actions > Uninstall app, you can also delete the data volumes. This permanently deletes all recorded data.

Manual installation

The rest of this guide covers a manual installation of Matomo with Docker Compose, for example, on a server without One-Click Apps. You’ll start Matomo and MariaDB in containers, expose Matomo only locally, set it up through an SSH tunnel, then make it accessible through nginx with a Let’s Encrypt certificate.

Requirements

MinimumRecommended
CPU1 vCPU core2 vCPU cores
RAM1 GB2 GB
Storage5 GB50 GB; grows with the data collected

According to Matomo, the recommended resources are enough for up to 100,000 page views per month with the application and database on one server. You’ll also need:

Prepare the firewall

Matomo only needs web ports to be accessible externally. Open SSH, HTTP, and HTTPS in ufw:

Code
sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Don’t open Matomo’s port. Docker bypasses ufw rules for published ports, so bind it to 127.0.0.1 in the Compose file. For more information about firewall rules, see VPS: Open Ports and Manage the Firewall on Linux.

Install with Docker Compose

Create a directory and generate an .env file with two random database passwords:

Code
sudo mkdir -p /opt/matomo && cd /opt/matomo
echo "DB_PASSWORD=$(openssl rand -hex 16)" | sudo tee .env
echo "DB_ROOT_PASSWORD=$(openssl rand -hex 16)" | sudo tee -a .env
sudo chmod 600 .env

Next, create the compose.yml file, for example, with sudo nano compose.yml:

Code
services:
  db:
    image: mariadb:lts
    restart: unless-stopped
    command: --max-allowed-packet=64MB
    environment:
      MARIADB_DATABASE: matomo
      MARIADB_USER: matomo
      MARIADB_PASSWORD: ${DB_PASSWORD}
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MARIADB_AUTO_UPGRADE: "1"
    volumes:
      - matomo-db:/var/lib/mysql

  app:
    image: matomo:5.14
    restart: unless-stopped
    depends_on:
      - db
    environment:
      MATOMO_DATABASE_HOST: db
      MATOMO_DATABASE_ADAPTER: mysql
      MATOMO_DATABASE_TABLES_PREFIX: matomo_
      MATOMO_DATABASE_USERNAME: matomo
      MATOMO_DATABASE_PASSWORD: ${DB_PASSWORD}
      MATOMO_DATABASE_DBNAME: matomo
    ports:
      - "127.0.0.1:8080:80"
    volumes:
      - matomo-app:/var/www/html

volumes:
  matomo-db:
  matomo-app:

The important lines:

  • mariadb:lts uses the current long-term support version of MariaDB. MARIADB_AUTO_UPGRADE automatically updates the system tables when the database is updated.
  • --max-allowed-packet=64MB increases the maximum size of a query, which Matomo needs when processing large reports.
  • matomo:5.14 is the official image with Apache and PHP. Find the latest version on Docker Hub.
  • The MATOMO_DATABASE_* values pre-fill the database step in the setup wizard. Matomo displays the password there only as asterisks.
  • 127.0.0.1:8080:80 makes Matomo accessible only on the server itself.
  • /var/www/html is stored in the matomo-app volume. Matomo stores its program files, configuration, and installed plugins there.

Start the containers:

Code
sudo docker compose up -d
sudo docker compose ps

First visit and setup wizard

Warning: Never leave the setup wizard open to the internet

Until setup is complete, anyone who can access Matomo can select the database and make themselves a Superuser. So complete the wizard through an SSH tunnel before making Matomo available through your domain.

Open an SSH tunnel to the server on your computer:

Code
ssh -L 8080:127.0.0.1:8080 root@SERVER_IP

Then open http://localhost:8080 in your browser and follow the wizard:

  1. Welcome and System Check: Click Next. You can ignore yellow warnings for now.
  2. Database Setup: The fields are already filled in. Select MariaDB under Database engine and click Next.
  3. Creating the Tables: Matomo creates the tables.
  4. Superuser: Set a username, a strong password, and your email address.
  5. Set up a Website: Enter the name, address, and time zone for your first website.
  6. JavaScript Tracking Code: You can retrieve the code again at any time.
  7. Congratulations: Leave Anonymize Visitors' IP addresses and Support Do Not Track preference enabled, then click Continue to Matomo.

Next, add your domain as a trusted address and tell Matomo that it’s running behind a reverse proxy. Otherwise, Matomo will reject the domain and store the proxy’s IP address for every visitor:

Code
cd /opt/matomo
sudo docker compose exec -u www-data app php console config:set 'General.trusted_hosts[]="analytics.example.com"'
sudo docker compose exec -u www-data app php console config:set 'General.proxy_client_headers[]="HTTP_X_FORWARDED_FOR"'
sudo docker compose exec -u www-data app php console config:set 'General.proxy_scheme_headers[]="HTTP_X_FORWARDED_PROTO"'

HTTPS access through a reverse proxy

Install nginx and Certbot:

Code
sudo apt install -y nginx certbot python3-certbot-nginx

Create the /etc/nginx/sites-available/matomo file:

Code
server {
    listen 80;
    server_name analytics.example.com;

    client_max_body_size 64M;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the site and obtain the certificate:

Code
sudo ln -s /etc/nginx/sites-available/matomo /etc/nginx/sites-enabled/matomo
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d analytics.example.com

Certbot adds the HTTPS block and redirects HTTP to HTTPS. Then open https://analytics.example.com and log in as your Superuser. For more information about the basics, see VPS: Set Up a Reverse Proxy with nginx on Linux and VPS: Create an SSL Certificate (Let's Encrypt).

Back up your data

All recorded visits and reports are in the database, while the program files and configuration are in the matomo-app volume. Back up both together with compose.yml and .env:

Code
cd /opt/matomo
sudo docker compose exec -T db sh -c 'mariadb-dump -u root -p"$MARIADB_ROOT_PASSWORD" --single-transaction matomo' | gzip > /root/matomo-db-$(date +%F).sql.gz
sudo tar -czf /root/matomo-app-$(date +%F).tar.gz -C /var/lib/docker/volumes matomo_matomo-app -C /opt/matomo compose.yml .env

Volume names start with the directory name, which is matomo_ in this example. Check them with sudo docker volume ls. Then copy the backup to another computer or storage location. A backup on the same server won’t protect you if the server fails.

Update Matomo

Because the program files are stored in the matomo-app volume, a new image alone won’t update Matomo. The image copies Matomo into the empty volume only on the very first start. Follow these steps:

  1. Back up your data as described above.
  2. Click New Update at the top of Matomo and start the built-in updater. It downloads the new version and updates the database.
  3. Update the web server, PHP, and MariaDB with a new image. If needed, enter a new version in compose.yml and restart:
Code
cd /opt/matomo
sudo docker compose pull
sudo docker compose up -d

If Matomo prompts you to update the database in your browser after the update, you can also run the update from the console:

Code
sudo docker compose exec -u www-data app php console core:update --yes

Add tracking and use Matomo day to day

Matomo only collects data once you add the tracking code. The following steps apply to both the One-Click App and the manual installation.

Add the tracking code to your website

  1. In Matomo, click the gear icon in the top right and select Websites > Tracking Code.
  2. Select the relevant website under Website.
  3. Copy the code from the JavaScript Tracking section and add it to every page of your website before the closing </head> tag.

Many systems have ready-made extensions that add the code for you. Matomo links to them on the same page, including extensions for WordPress, Joomla, and Shopify, as well as for Google Tag Manager. To check whether data is coming in, go to Visitors > Visits Log in Matomo: visit your website, and your visit should appear there after a few seconds.

Tip: Turn off ad blockers while testing

Some ad and tracking blockers filter matomo.js and matomo.php. If you can’t see your own visit, try another browser or disable your extensions.

Archive reports with cron

Matomo first stores each individual visit, then uses that data to calculate reports. By default, it does this when you open a report in your browser, at most every 900 seconds. With more visitors, reports can take noticeably longer to load. In this case, Matomo recommends generating reports hourly with a cron job and disabling browser archiving.

First, use SSH to find the name of the Matomo container. For the One-Click App, it starts with app-:

Code
docker ps --format '{{.Names}}  {{.Image}}' | grep matomo

Open the server’s crontab with crontab -e and add a line with the container name and your Matomo address:

Code
5 * * * * docker exec -u www-data CONTAINER_NAME php /var/www/html/console core:archive --url=https://analytics.example.com/ > /dev/null 2>&1

For the manual installation, the container name is usually matomo-app-1. Once the cron job is running, go to System > General settings > Archiving settings in Matomo, set Archive reports when viewed from the browser to No, and save. To check whether archiving is working, look at Archive Time Last Finished under Diagnostic > System Check.

Privacy settings

Matomo includes the most important settings for minimizing data collection. Find them by clicking the gear icon and selecting Privacy:

  • Anonymize data: Choose how many bytes Matomo removes from IP addresses. Two bytes are recommended and enabled by default in the One-Click App. You can also set Matomo to automatically delete old visit data.
  • Users opt-out: Provides code for your privacy policy that lets visitors opt out of tracking.
  • Asking for consent: Explains how to connect Matomo to a consent banner so tracking starts only after a visitor gives consent.
  • GDPR Tools: Find, export, or delete data for individual visitors, for example, in response to data access requests.

Matomo can also collect data without using cookies. To do this, add the line _paq.push(['disableCookies']); to the tracking code before the line containing trackPageView. Matomo will then be less accurate at recognizing returning visitors.

Info: This is not legal advice

Whether you need visitors’ consent to use Matomo depends on your configuration and the laws in your country. Matomo explains the options under Privacy > Understanding your legal obligations. In any case, mention Matomo in your privacy policy and seek legal advice if you’re unsure.

Limitations

  • Country detection is inaccurate without a geolocation database: By default, Matomo estimates a visitor’s country based only on their browser language. Set up a geolocation database under System > Geolocation, such as the free DB-IP database, and have it update automatically. With two anonymized bytes, city-level location is still inaccurate.
  • Many extra features cost extra: Find more plugins under Plugins in Matomo. Popular features such as heatmaps and session recording are paid Matomo premium plugins.
  • No emails without SMTP: Scheduled reports by email and password resets won’t work until you enter an SMTP server.

Conclusion

You’ve set up Matomo on your VPS, added your website, installed the tracking code, and configured reports to be archived with cron. You can now analyze visits to your websites without sharing data with a third-party provider.

Prefer to skip the Docker setup? Choose the easy One-Click App option described above under “Easy option: Matomo as a One-Click App.”

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

For most people, the One-Click App is the quickest option: Matomo runs at your address over HTTPS in just a few minutes, with the database and admin account set up and actual visitor IPs detected correctly. Manual installation with Docker Compose is useful if you’re running Matomo on a server without One-Click Apps or want to manage the database and reverse proxy yourself.
For the One-Click App, find them in the app settings under App Environment > Automatically Generated Values. The username is in the SERVICE_USER_MATOMO field and is zapx; the password is in the SERVICE_PASSWORD_MATOMO field. For a manual installation, you create the Superuser account yourself in the setup wizard.
That depends on your configuration and the laws in your country; we can’t provide legal advice. Matomo offers several tools: tracking without cookies, IP address anonymization, an opt-out for your privacy policy, and integration with a consent banner. You can find explanations under Privacy in Matomo.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.