From 40de3572c90a956f9db02d14f86b34e812042ace Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Wed, 16 Sep 2026 11:36:46 +0200 Subject: [PATCH 1/2] Support list configuration values via JSON arrays Configuration options which expect a list of values are now supported by JSON arrays in environment variables. In case JSON parsing fails, the environment variable value is used literally just like before. --- README.md | 12 ++++++++++-- config/config.php | 9 ++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0eea0a4..99ef5f9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Description -Override any Matomo config with environment variables. To overwrite any setting simply specify an environment variable in the following format: +Override any Matomo config with environment variables. To overwrite any setting, specify an environment variable in the following format: ``` MATOMO_$CATEGORY_$SETTING @@ -23,8 +23,16 @@ export MATOMO_DATABASE_USERNAME=root export MATOMO_DATABASE_PASSWORD=secure ``` +List values can be set via encoded JSON arrays: + +```bash +export MATOMO_GENERAL_TRUSTED_HOSTS='["1.2.3.4","5.6.7.8"]' +``` + +Any other type of value is used literally. The same applies to JSON values which fail to decode. + ### Known issues: -* Configuration arrays are currently not supported, for example you cannot define which `Plugins[]` should be loaded. + * At some point your Matomo may save/write the config file, for example when changing certain settings through the UI such as the trusted hosts. In this case, the currently read environment variables will be saved in the config file. * If this plugin is used with PHP-FPM, for example in combination with NGINX, PHP-FPM will not have access to the environment variables by default. The pool used by PHP-FPM must either explicit define which ENVs should be exposed, or set `clear_env = no` in `/etc/php7/php-fpm.f/.conf`. * When defining the database credentials as environment variables, you may have to hard code the configs indicating that this plugin is activated, like the following: diff --git a/config/config.php b/config/config.php index e808a99..e4567fc 100644 --- a/config/config.php +++ b/config/config.php @@ -21,8 +21,15 @@ $envValue = getenv($settingEnvName); if ($envValue !== false) { + try { + $decodedEnvValue = json_decode($envValue, true, 512, \JSON_THROW_ON_ERROR); + $settingValue = is_array($decodedEnvValue) ? $decodedEnvValue : $envValue; + } catch (\JsonException) { + $settingValue = $envValue; + } + $general = $previous->$category; - $general[$settingName] = $envValue; + $general[$settingName] = $settingValue; $previous->$category = $general; } } From 68fd1f9a53fd8fb5f07a5d92dd41fa277ad65f46 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Fri, 2 Oct 2026 10:40:20 +0200 Subject: [PATCH 2/2] Bump version to 6.0.1 --- CHANGELOG.md | 3 +++ plugin.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5874680..1aa3d2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### 6.0.1 - 2026-10-06 +- Support list configuration values via JSON arrays, e.g. for `trusted_hosts` via `MATOMO_GENERAL_TRUSTED_HOSTS=["example.com","example.net"]` + ### 6.0.0 - 2026-08-10 - Compatibility with Matomo 6 diff --git a/plugin.json b/plugin.json index 1988b18..39591c0 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "name": "EnvironmentVariables", "description": "Allows you to specify Matomo config in environment variables instead of the config file.", - "version": "6.0.0", + "version": "6.0.1", "theme": false, "require": { "matomo": ">=6.0.0-b1,<7.0.0-b1"