Security & hardening

An analytics instance holds data about your visitors and is often publicly reachable. I review Matomo, PHP, web server and operating system with tools such as Lynis, harden the instance following proven guidelines and back up the result with a before and after report. Hardening means switching off whatever is not needed and configuring everything else so that attackers find as little to attack as possible.

How I work

  1. 01Review Matomo, clean up access, roles and tokens
  2. 02Harden the operating system, trim packages and services
  3. 03Configure PHP and web server securely
  4. 04Check with Lynis and co., set up an update process and an incident plan

Securing Matomo itself

  • Current Matomo and plugin versions, unused plugins removed
  • Two-factor login required for all users, single sign-on, roles following least privilege
  • Brute force detection and a notice for logins from another country
  • API tokens cleaned up, agency and legacy accounts removed
  • Configuration files, logs and temporary directories not reachable from outside

Matomo settings in config.ini.php

Some settings are not in the interface but in the file config/config.ini.php. These belong to a hardened instance:

  • force_ssl = 1 Matomo redirects every request to HTTPS.
  • login_allowlist_ip Login and the Reporting API only from defined networks, while tracking stays reachable.
  • only_allow_secure_auth_tokens = 1 API tokens are only valid in POST requests, not as a parameter in a URL.
  • enable_installer = 0 The installation wizard is switched off after setup.
  • enable_plugin_upload = 0 Plugins cannot be uploaded through the interface, as in the default setting.

Protected directories in nginx and Apache

Directories such as config, tmp, core and lang, the file config/config.ini.php and a .git directory must not be reachable from the internet. Matomo’s System Check tests this under “Required Private Directories” and “Recommended Private Directories”.

  • Apache Matomo ships .htaccess files for these directories. They only take effect if the web server evaluates them via AllowOverride.
  • nginx .htaccess files do not apply here. The blocks belong in the server configuration, ideally following Matomo’s official example configuration, which only allows the PHP files that are needed.
  • nginx in front of Apache In hosting panels such as Plesk, nginx often serves static files itself, so Apache’s .htaccess does not apply. The blocks also belong in the nginx configuration.
  • Check after every change Run the System Check again and open the addresses once in a browser.

Central login and traceability

  • Single sign-on via LDAP or SAML 2.0, for example with Entra ID, Okta or Keycloak, permissions from directory groups
  • Accounts created and locked automatically via SCIM when someone leaves the company
  • A log of who changed which setting (Activity Log)
  • Separate accounts for agencies and service providers, removed when the project ends

Separating Matomo tracking and interface

The tracking endpoint has to be reachable for every visitor of the measured websites, the interface does not. Login and reports can be limited to the company network or a VPN while the tracker stays public. For larger instances, tracking and reports run on separate servers, keeping the public part as small as possible.

Matomo updates and new security flaws

Many attacks exploit known flaws in outdated software. Matomo, plugins, PHP, web server and database therefore need a fixed update process: follow security notices, install updates on a test instance first and then promptly on live, restart services and check the versions. Critical flaws do not belong in the next maintenance window. For the PHP flaws in October 2026, the German BSI expected attacks within a few hours; more in the post PHP2Shell: update your Matomo server now.

Operating system and packages

  • System check with Lynis, complemented by package and update checks
  • Remove packages and services that are not needed, close open ports
  • Automatic security updates, for example with unattended-upgrades
  • SSH with keys only, no direct root login, fail2ban and a firewall
  • Access control with AppArmor (Debian, Ubuntu) or SELinux (Red Hat, Rocky, Alma): web server and PHP-FPM may only access the directories, files and services Matomo needs. What this contains in a flaw like PHP2Shell, and what it does not, is covered in the PHP2Shell post
  • File and directory permissions as tight as possible

PHP, web server and database

  • A current PHP version, expose_php and display_errors off
  • Functions that are not needed disabled, open_basedir and secure session settings
  • Up-to-date TLS, security headers, rate limits for login and API
  • Admin interface restricted to certain networks or a VPN if required
  • A dedicated database user with only the permissions Matomo needs, no access to the database from outside
  • Backups encrypted and stored separately, restores tested regularly

Web application firewall with a suitable ruleset

A web application firewall checks requests before they reach PHP and Matomo.

  • Ruleset ModSecurity or Coraza with the OWASP Core Rule Set, or alternatively the managed rules of Cloudflare or another CDN.
  • Tuned for Matomo Tracking requests and the Reporting API contain long parameters, URLs and JSON that standard rules easily treat as attacks. Exclusions apply specifically to these endpoints.
  • Gradually stricter Log only at first, then block, and raise the Core Rule Set’s paranoia level step by step.
  • Bridging new flaws With suitable rules, a WAF holds off known attacks until the update. It does not replace the update.

If something does happen

  • Isolate Take the server offline or block access, preserve the web server, PHP and database logs.
  • Check File integrity in Matomo’s System Check, users with super user access, API tokens, cron jobs and new files in the web directory.
  • Renew Reset passwords, API tokens and database credentials, reinstall Matomo from the official package and republish the Tag Manager containers.
  • Report Involve data protection early, because access to visitor data can trigger a notification duty under the GDPR.

Evidence

You get the reports from before and after hardening, a list of measures and a plan for updates and backups. That lets you show IT security and auditors what is configured.

Server check

From the operating system to the Matomo configuration.

Lynis checks packages, services, SSH, PHP and much more and sums up the result in a hardening index. We compare it before and after hardening. The output shown here is an example.

root@matomo: ~
$ lynis audit system
            [+] Boot and services
            
          
              - Service Manager
            [ systemd ]
          
            [+] Software: PHP
            
          
              - Checking expose_php option
            [ ON ]
          
              - Checking PHP disabled functions
            [ NONE ]
          
            [+] SSH Support
            
          
              - SSH option: PermitRootLogin
            [ SUGGESTION ]
          
              - SSH option: PasswordAuthentication
            [ SUGGESTION ]
          
            [+] Software: firewalls
            
          
              - Checking host based firewall
            [ ACTIVE ]
          
            [+] Packages
            
          
              - Checking for upgradeable packages
            [ FOUND ]
          
Hardening index, before58
Hardening index, after86
  • Operating system and packages
  • SSH, firewall and fail2ban
  • PHP settings
  • Web server, TLS and headers
  • Matomo, roles and tokens
  • Updates and backups

FAQ

Frequently asked questions

What do you check on the server?

The operating system and installed packages, open services and ports, SSH, firewall, updates and the settings of PHP, web server and database. Lynis provides a structured overview with a hardening index, which I assess and work through together with your IT team.

Do you need root access for this?

For a complete system check yes, limited in time and ideally with your IT team present. Alternatively your IT team runs the checks following my instructions and I evaluate the reports.

How quickly should security updates be installed?

Critical flaws on the same day. For the PHP flaws in October 2026, the German BSI expected attacks within a few hours of the patches being released. Less critical updates can go into the regular maintenance cycle.

Can the Matomo interface sit behind a VPN?

Yes. With login_allowlist_ip in config.ini.php, login and the Reporting API can be limited to certain networks. The tracking endpoint, however, has to stay reachable for every visitor of the measured websites.

Is a web application firewall enough?

A WAF such as ModSecurity or Coraza with the OWASP Core Rule Set adds protection, but it replaces neither updates nor a clean configuration. For Matomo the ruleset needs exclusions so that tracking requests and the Reporting API are not blocked.

Do you also run penetration tests?

sonora reviews and hardens configuration and servers. Formal pentests during operations are offered by our sister brand feinwerk.io as part of its SLA operations.

Knowledge on this topic

Guides on this topic

Related

Questions about this?

In an intro call we'll clarify where you stand and whether I'm the right fit.

Your contactPeter Boehlke, Matomo consultant from Munich, 17 years in the Matomo team

Newsletter

Matomo know-how, once a month.

Practical tips on tracking, privacy settings and performance, plus notes on important Matomo updates. No spam, unsubscribe any time.