Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set External Parameters using PHP Built-In Server #10208

Closed
ryan0x44 opened this issue Feb 5, 2014 · 3 comments
Closed

Set External Parameters using PHP Built-In Server #10208

ryan0x44 opened this issue Feb 5, 2014 · 3 comments
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) HttpKernel

Comments

@ryan0x44
Copy link

ryan0x44 commented Feb 5, 2014

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

@marfillaster
Copy link
Contributor

a simple check php_sapi_name() == 'cli-server' in Kernel::getEnvParameters can be used to switch lookup from $_SERVER to $_ENV

fabpot added a commit that referenced this issue Aug 8, 2014
…r built-in server (mauchede)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #10914).

Discussion
----------

[HttpKernel] added an analyze of environment parameters for built-in server

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #10208
| License       | MIT
| Doc PR        | -

With the built-in server, it is not possible to use the external parameters: environment variables are only in `$_ENV`.

Commits
-------

696b978 [HttpKernel] added an analyze of environment parameters for built-in server.
@fabpot fabpot closed this as completed Aug 8, 2014
@ryan0x44
Copy link
Author

Awesome thanks for the fix @fabpot!

@bicpi
Copy link
Contributor

bicpi commented Sep 25, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) HttpKernel
Projects
None yet
Development

No branches or pull requests

5 participants