Dev Exceptions shown in production

I know this is a big NO NO ... and the developer error pages should not be displayed while my site is alive, what can I do to prevent dev environment error messages from appearing during production?

enter image description here

Why do they appear? I thought it was disabled by default in production mode? Did I skip the setup?

Note. . This is on a shared server. And I use app.php not app_dev.php.

When I go into production mode, it correctly displays the correct error messages (below):

Oops! An error has occurred. The server returned "404 Not Found." Something broke. Send us an email and let us know what you did when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience.

However, on a live site, a Symfony2 dev environment error message is displayed?

I tried to create my own error message by creating the error404.html.twig file in the application / Resource / TwigBundle / views / Exception , but it still does not load this file and just displays the developer error message.

+6
source share
1 answer

An instance of AppKernel is created in your front-end controller ( web/app.php in Symfony Standard Edition). AppKernel inherits the constructor from Symfony 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 one that enables or disables debugging (and therefore determines which exceptions are thrown, 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 convenient error pages.

+11
source

All Articles