Error displaying 500 errors with any error in apache

Possible duplicate:
How to get PHP to set the HTTP status code to 500 automatically in case of any errors? (including those that cannot be processed by the user)

I want to configure Apache to send the user a 500 response with a user page of 500 when a PHP script causes a fatal error. Now I have what it prints an error in the line with the content of the page, which is good for development, but not for production.

How do I configure Apache to send a 500 response to a user using a custom page?

+2
source share
3 answers

Assuming that you not only want to send the 500 header (which is very simple), but to actually trigger a 500 error on the Apache system, there seems to be no trivial solution.

According to this question , this is the default PHP behavior with PHP 5.2.4 if:

  • a fatal error occurs and
  • document body is empty (Gordon found an entry in the change log here ).

I am not sure how reliable this behavior is in the long run (i.e. when PHP 6 appears, etc.). This is not a very advertising feature.

Other than that, I don't know how to provoke 500 after running the script. 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 this, of course, will not be logged.

+1
source

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 displays correctly even when strange things interfere with the drawing of PHP pages.

To invoke the error page, you look at this anser: How to return HTTP 500 code on any error, no matter what

0
source

I want to do the same, but I do not think this is possible with the current version of PHP. Firstly, there is an error in which 500 errors return the status of 200 . Therefore, installing ErrorDocument 500 in your configuration file will have no effect. In addition, it seems that it is not possible to access error information (for user display and logging), even if it can be redirected.

Running errors is easy. Just add this to your PHP file:

 throw new Exception(); 
0
source

Source: https://habr.com/ru/post/920163/


All Articles