piwikpro/env-params-builder-bundle
A Symfony bundle from Piwik PRO that helps build and manage environment-specific parameters, making it easier to configure services and integrations from environment variables in a consistent, maintainable way across development, staging, and production environments.
composer require piwikpro/env-params-builder-bundle
app/AppKernel.php (for Symfony 2/3):
$bundles = [ /* ... */ new PiwikPro\Bundle\EnvParamsBuilderBundle\EnvParamsBuilderBundle() ];
*:build / *:generate command). The DependencyInjection/Configuration.php is the authoritative reference for the mapping format.parameters.yml.dist as the template and treat the generated parameters.yml as a build artifact.cache:clear so the container is compiled against the env-var-derived parameters.composer.json:
"scripts": {
"post-install-cmd": ["@build-params"],
"post-update-cmd": ["@build-params"],
"build-params": ["php app/console env-params:build"]
}
This makes every deploy that runs composer install produce a correct parameters.yml without a manual step.composer install --no-dev (triggers builder) → cache:clear --env=prod → cache:warmup --env=prod → run. Skipping warmup leaves you with stale parameters from a previous release.SYMFONY__DATABASE_HOST) and reuse them across dev/staging/prod. The bundle reads whatever the process sees, so the mapping config should not branch on environment unless you deliberately override for local dev.parameters.yml for developer machines, and only regenerate in CI. Otherwise a fresh clone without env vars produces a broken file with empty values.parameters.yml per Symfony kernel and pass the output path explicitly if the command supports it.%env() technology. Symfony 3.2+ ships natively with %env(FOO)% and env() in parameters.yml, which makes this bundle redundant in modern apps. Use it only to maintain legacy codebases, not for greenfield work.cache:clear. A common bug is "I changed the env var and nothing happened" — that is almost always a warmed cache.:, #, %, @, or leading/trailing spaces need quoting. If the bundle writes raw string values, values like p@ss:word can corrupt the file. Inspect the generated file and, if needed, wrap sensitive-looking values in single quotes in your source data.null or "" rather than throwing. Add an explicit validation step in your deploy script (or a smoke test that hits a key endpoint) so a missing var fails loudly at deploy time, not at first request.parameters.yml.dist, gitignore parameters.yml, and document the env vars in a .env.example. Committing the generated file is how secrets leak.deploy, sometimes www-data). If web and deploy users differ, the generated file can end up unreadable by PHP-FPM. chmod 640 and align group ownership in your deploy script.-vvv, then diff the output against parameters.yml.dist. Most failures are a mapping typo (env var name mismatch) or a value type mismatch (string vs. boolean vs. int) — PHP's %parameter% substitution does not coerce types, so "false" stays a truthy string.Resources/config/services.yml), you can decorate or replace it to add custom normalization — e.g. casting "true"/"false" to booleans, or JSON-decoding a packed env var. This is cleaner than post-processing the generated YAML.%env()% + Symfony Flex's .env loading. The two approaches conflict if run together, and dual mechanisms make the effective value of a parameter hard to reason about.How can I help you explore Laravel packages today?