Lumen and PHP-FPM: where should production configuration enter?
0 reputation · 09 Dec 2023, 18:08 UTC
0 reputation · 09 Dec 2023, 18:08 UTC
Assuming Lumen 5.8 deployed behind Nginx with PHP-FPM, the goal is to define one authoritative source for production configuration without masking values supplied by the hosting layer. Lumen supports loading a .env file during bootstrap, while PHP-FPM can also expose environment variables to worker processes.
The integration boundary is not fully determined by Lumen alone. Process configuration, the application’s working directory, and whether configuration caching is enabled can affect which values are available. A configuration that works locally therefore does not establish the production source or precedence.
The deployment contract should keep secrets out of version control, avoid exposing values through diagnostics, and make a non-sensitive configuration key comparable across environments. A minimal endpoint could support that cross-environment check without revealing credentials.
Should PHP-FPM environment variables be the authoritative production source, with .env reserved for local defaults, or should production rely on a securely provisioned .env file? When configuration caching is enabled, what source precedence should the deployment contract require?
35775 reputation · 09 Dec 2023, 19:02 UTC
Make PHP-FPM pool environment variables the single authoritative source for production configuration. Reserve .env exclusively for local development defaults. When configuration caching is enabled, build the cache in the production environment with the FPM-provided variables present and no production .env file; after the cache is built, config() reads only the cached values and later changes to either source are inert until the cache is rebuilt.
env[VAR]=value in the pool configuration is the deliberate, auditable injection point for the hosting layer..env during bootstrap. If a production .env exists and the dotenv loader overwrites existing environment variables, it can silently override the FPM values. Omitting the file (or using a non-overwriting loader) guarantees FPM values take precedence.When php artisan config:cache runs, it resolves all env() calls at that moment and serializes the resulting configuration array. The cache file becomes the sole source for config() thereafter. Therefore:
.env)..env will be ignored until the next cache rebuild..env absent or root-owned 0600 and non-authoritative (dotenv loader set to not overwrite).APP_DEBUG=false in FPM env.env() only inside config/*.php files; never in request paths.config('app.env'), config('app.debug'), config('cache.default'), or a custom deploy.config_stamp) for cross-environment verification.bootstrap/app.php, confirm the exact dotenv call (e.g., Dotenv::createImmutable(...)->load() vs Dotenv::createMutable(...)->load()) and the .env path.clear_env setting and that required env[...] entries exist.config('app.env') === 'production' and getenv('DEPLOY_CONFIG_STAMP') !== false; remove after verification.Can your hosting layer set env[...] directives in the PHP-FPM pool or set clear_env = no? If the answer is no, you cannot rely on FPM pool vars as the authoritative source. In that case, fall back to a single securely provisioned .env file (root-owned, 0600, deployed via secret management) as the sole production source, and still build the config cache with that file present.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.