Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get PHP to display Apache's 500 error page when it encounters an error, instead of a blank page?

I have apache directives set up for custom error docs for 404, 403, etc, as well as 500. However, PHP, upon encountering a fatal error, displays a blank page instead of triggering the apache 500 response.

I don't need to display the error details or anything like that, as they are currently logged correctly in apache error_logs, so I don't think it has anything to do with error_reporting or display_errors, both of which are set correctly.

There are some similar questions here on SO, but haven't found an answer that does what I need. Basically, in the case of something like a syntax error, I want to see the apache 500 error page, NOT a blank page. This is not something that can be caught and handled in PHP, since syntax errors are uncatchable.

This appears to have been patched/fixed in php 5.2.4, as seen here: http://www.mail-archive.com/[email protected]/msg28557.html

However, we are using PHP 5.2.17, and an upgrade is not feasible at this time. Does anyone have any solutions / workarounds that might work to trigger 500 errors in apache for any PHP syntax/fatal error?

like image 342
Kevin Jhangiani Avatar asked Jul 14 '11 02:07

Kevin Jhangiani


1 Answers

Not sure if this works: register a shutdown handler and display the appropriate page. The shutdown handler should get called whenever a fatal error occurs. Make sure that you register the handler on top of your script.

like image 163
towe75 Avatar answered Nov 14 '22 23:11

towe75