Description
Hello,
I have found an issue with setting parameters externally (as explained on the "How to Set External Parameters in the Service Container" page) using PHP 5.4's built-in server.
If you refer to this StackOverflow question and this GitHub issue, you can see that the variables-order INI directive must be set to include "E" so that you can set environment variables like so:
export SYMFONY__DATABASE__PASSWORD="password"
php -d variables_order=EGPCS -S 0.0.0.0:8080 -t . test.php
This works fine, and SYMFONY__DATABASE__PASSWORD
can be accessed via getenv('SYMFONY__DATABASE__PASSWORD')
and $_ENV['SYMFONY__DATABASE__PASSWORD']
.
The problem is,
- Setting env variables through Nginx will set them in
$_ENV
and$_SERVER
- Setting env variables through the built-in server will set them in
$_ENV
but not in$_SERVER
The variables-order INI directive documentation contains the following warning:
"In both the CGI and FastCGI SAPIs, $_SERVER is also populated by
values from the environment; S is always equivalent to ES regardless
of the placement of E elsewhere in this directive."
The Symfony HttpKernel will only load the environment variables if they exist in $_SERVER, and not if they exist in $_ENV.
See the getEnvParameters() method in src/Symfony/Component/HttpKernel/Kernel.php.
If $_ENV was included in this method, I believe this would resolve the issue.
If there is an alternative solution, please let me know! :)
Cheers,
Ryan