Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/<pool>.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:
Expand Down
9 changes: 8 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading