3

Apache does not want to display a custom error document that I have setup.

In my vhost I have

    DocumentRoot /var/www/site/public
    ...
    ErrorDocument 500 /500.html

The 500.html is located in /var/www/site/public/500.html

To test this I have just created a broken php page that does return a 500 header but the page is blank. I suspect that this is a result of php generating the 500 page and not apache. So how do I get php to show my custom apache error document?

2

This is normal behavior, as PHP errors aren't considered 5xx Server Errors. According to RFC 7231

6.6. Server Error 5xx

The 5xx (Server Error) class of status code indicates that the server is aware that it has erred or is incapable of performing the requested method. - -

6.6.1. 500 Internal Server Error

The 500 (Internal Server Error) status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

PHP errors should always be fixed as they may pose you security problems. For the same reason best practise in handling php errors is to log them for the programmers to review and hide them from users. This kind of setup would be (in php.ini format):

error_reporting = E_ALL
log_errors = On
display_errors = Off

This will log errors in web server's error log or in other error log configured. Instead of reading them from the site you can perform tail -f on the log file during loading the page.

  • This answer makes no sense. One cannot "fix" an error the same instant it occurred. And setting display_errors to off will trigger the very 500 error that this very question is about. – Col. Shrapnel Sep 8 '17 at 13:46
  • The error will be in logs... where it should be. – Esa Jokinen Sep 8 '17 at 13:48
  • The question here IS NOT about where the text of the error message should be but what should be displayed to a site user. There are some strange people that are browsing your site, you know – Col. Shrapnel Sep 8 '17 at 13:49
  • PHP will show blank page / section, depending on the case. This answer is from 2015. At least back then there weren't any 5xx errors regarding errors in PHP syntax. – Esa Jokinen Sep 8 '17 at 13:52
  • 1
    I will. But when I see a hosting provider support referencing this answer... WTF? – Col. Shrapnel Sep 8 '17 at 14:03

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.