Skip to content

[Commands] server:run ignores environment #7430

genexp opened this Issue Mar 20, 2013 · 7 comments

4 participants

genexp commented Mar 20, 2013


When I use:

php app/console --env=prod server:run 

I would expect Symfony to run in production mode. However, it continues to load my config_dev.yml.


Having this work properly would be useful in many situations, testing custom error pages for example, which won't load in development. This also maps mentally to other popular web frameworks that support running using a languages built in web server in any mode supported by the framework.


It appears that Symfony2 loads the simple router bundled with the Framework Bundle, which in turn always loads app_dev.php. The offending line is here:

The server:run command DOES allow you to load a custom router, but this seems inappropriate in this situation. For something like production mode, it should simply work as you'd expect.

I'm not familiar enough with the underbelly of Symfony2 to actually fix this. Any thoughts?


I once expected the same behavior as you did. But then I realized that the --env-option is the context for the command itself and not for the server it runs. So the command itself would run in a prod-enviroment and the php-server would start a seperate dev-enviroment on each request coming in.

So this is expected behaviour. Anyway, I think there should be a clean, documented way to switch between various enviroments for the server and to cleanup such confusions...


For the moment you have to implement your own router. You have to copy the router.php from vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/router.php to something like app/config/router_prod.php, change app_dev.php to app.php and run it with ./app/console server:run --router=app/config/router_prod.php.

Symfony member
stof commented Mar 22, 2013

@genexp you should not use server:run for production anyway as the PHP built-in webserver is not meant to be used for prod


@stof: Thats obviously true! But there are situations where it is nice to have the chance to test something with a single command in production-mode. For example: quickly verify cache-settings.

I think at least there should be a notice in the command that the --env-switch does not effect the running server.

@fabpot fabpot added a commit that referenced this issue Apr 9, 2013
@fabpot fabpot merged branch canni/prod_server (PR #7507)
This PR was squashed before being merged into the master branch (closes #7507).


[FrameworkBundle] Enable possibility to run PHP bultin server in production env

See the referenced ticket for discussion;

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


12fce13 [FrameworkBundle] Enable possibility to run PHP bultin server in production env
@fabpot fabpot closed this Apr 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.