Dev Exceptions are shown in production environment

淺唱寂寞╮ 提交于 2019-12-22 04:58:09

问题


I know this is a big NO NO... and should not be displaying developer error pages while my site is live, what can I do to ensure dev environment error messages are not appearing in production?

Why are these appearing? I thought it was turned off by default when in production mode? Did I miss a setting?

Note: This is on a shared server. And am using the app.php not app_dev.php.

When I go to production mode locally it properly displays the right error messages (below):

Oops! An Error Occurred The server returned a "404 Not Found". Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

Yet on the live site it's showing the Symfony2 dev environment error message?

I've tried to make a custom error message by making a error404.html.twig file in app/Resource/TwigBundle/views/Exception but it still doesn't load this file and just displays the developer error message.


回答1:


In your frontend controller (web/app.php in the Symfony Standard Edition), an instance of AppKernel is created. AppKernel inherits the constructor from Symfony's Kernel, which requires two arguments:

/**
 * Constructor.
 *
 * @param string $environment The environment
 * @param bool   $debug       Whether to enable debugging or not
 */
public function __construct($environment, $debug)

The $environment parameter only determines which configuration is used (config_dev.yml, config_prod.yml, etc.). The $debug parameter is the one that enables or disables debugging (and therefore determines wether exceptions are shown or not).

So in app.php, change:

$kernel = new AppKernel('prod', true);

to

$kernel = new AppKernel('prod', false);

This should replace the detailed exception pages with user-friendly error pages.



来源:https://stackoverflow.com/questions/23335375/dev-exceptions-are-shown-in-production-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!