Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Commands] server:run ignores environment #7430

Closed
genexp opened this Issue · 7 comments

4 participants

@genexp

Issue

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.

Rationale

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.

Research

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:

https://github.com/symfony/FrameworkBundle/blob/master/Command/ServerRunCommand.php#L84

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?

@benbender

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...

@genexp
@benbender

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.

@genexp
@stof
Collaborator

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

@benbender

@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.

@genexp
@fabpot fabpot referenced this issue from a commit
@fabpot fabpot merged branch canni/prod_server (PR #7507)
This PR was squashed before being merged into the master branch (closes #7507).

Discussion
----------

[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

Commits
-------

12fce13 [FrameworkBundle] Enable possibility to run PHP bultin server in production env
17e065f
@fabpot fabpot closed this
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.