How to keep the config file and tracker JS files in sync in multi-server environment?
When running Matomo on multiple servers it is required to synchronise the following files across all servers:
/matomo.js and /piwik.js
/js/container_*.js
/misc/user/*
/config/config.ini.php
How to keep these files in sync?
To keep all files synchronised, one could use NFS (with local file caching enabled), or any other shared storage in order to share these files across all servers as long as it is using some local cache (for read performance) and is highly available.
Alternative solution: manually synchronise files across all servers after they are changed
Because there can be performance or operational complexities around using shared network disks, we can also recommend this alternative solution which does not require using NFS or shared network storage.
-
When you deploy Matomo on multiple servers, you will want to make sure that you manually deploy the
/config/config.ini.php
to all servers whenever they are modified. Theconfig.ini.php
file will not get updated from the UI as long this setting is set:multi_server_environment = 1
but there are still actions (all require Super User permission) that will update theconfig.ini.php
file.
You need to manually re-deploy the config.ini.php file to all servers whenever one of these events occur:- after a successful Matomo upgrade.
- after installing or activating a new plugin.
- after de-activating a plugin.
- after configuring LDAP plugin settings if you use LDAP for Single Sign On.
-
You need to deploy the
/misc/user/*
files across all servers whenever a Super User uploads a custom logo or favicon.
You need to run a crontab every minute which will re-generate the files /matomo.js
and /js/container_*.js
and make sure they are synchronised across all servers and up to date. Add the following lines to your crontab:
# Re-generate Matomo JavaScript Tracker file
* * * * * php /path/to/matomo/console custom-matomo-js:update
--no-ansi > /dev/null
# Re-generate Matomo Tag Manager containers
* * * * * php /path/to/matomo/console
tagmanager:regenerate-released-containers --no-ansi > /dev/null