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,
$_ENV
and $_SERVER
$_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
a simple check php_sapi_name() == 'cli-server'
in Kernel::getEnvParameters
can be used to switch lookup from $_SERVER
to $_ENV
Awesome thanks for the fix @fabpot!
Is there a reason why the server:run
command does not allow to change php.ini
settings using the PHP binary -d
flag?
To work around the PHP issue with $_ENV
/$_SERVER
mentioned above I do not want to change my php.ini
, I just want to do something like this:
SYMFONY__MY__PARAM=Foobar php -d variables_order=EGPCS -t web -S 127.0.0.1:8000 `pwd`/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php
I would prefer using server:run
but I'm not able to pass the -d variables_order=EGPCS
part.
Most helpful comment
Is there a reason why the
server:run
command does not allow to changephp.ini
settings using the PHP binary-d
flag?To work around the PHP issue with
$_ENV
/$_SERVER
mentioned above I do not want to change myphp.ini
, I just want to do something like this:I would prefer using
server:run
but I'm not able to pass the-d variables_order=EGPCS
part.