tags:

views:

28

answers:

2

I want to configure Apache to send to the user a 500 response with a custom 500 page when a PHP script raises a fatal error. What I have now is that it will print the error inline with the page content which is good for development but not for production.

Thanks in advance.

P.S.:any good tutorial on how to tune php/apache for production usage?

A: 

I would say that

ErrorDocument 500 /some/page.php

should do the trick, or just a nice HTML page if you want to be sure that it renders properly even when strange things are preventing PHP pages to render.

In order to trigger the error page you look at this anser : http://stackoverflow.com/questions/3052715/php-how-to-return-an-http-500-code-on-any-error-no-matter-what

Peter Tillemans
The OP is looking to trigger a 500 when the PHP script raises a fatal error.
Pekka
A: 

Assuming that you don't only want to send a 500 header (which is easy), but really trigger a 500 error in Apache's system, there seems to be no trivial solution.

According to this question, it is PHP's default behaviour since PHP 5.2.4 if 1.) a fatal error occurs and 2.) the document body is empty (Gordon found the changelog entry here).

I'm not sure how reliable this behaviour is long term (i.e. when PHP 6 comes up etc.). It's not a much advertised feature.

Other than that, I know of no way of provoking a 500 once the script runs. I asked something similar for 404s once. The answer provided there (redirecting to a predefined URL, and sending a 500 header) may be the best you can get - although that of course won't be logged.

Pekka