How I work
- 01Review Matomo, clean up access, roles and tokens
- 02Harden the operating system, trim packages and services
- 03Configure PHP and web server securely
- 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.
