Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dev Exceptions are shown in production environment

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?

enter image description here

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.

like image 627
dizzyd Avatar asked Apr 28 '14 07:04

dizzyd


1 Answers

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.

like image 54
Nic Wortel Avatar answered Nov 16 '22 06:11

Nic Wortel