3

As the Question title suggests, I want to setup a custom 500 error. In fact, I want to use a .php file for the error, and ideally send a 503 response (SE Reasons).

The problem is that the only way I know to generate a 500 response is via .htaccess, and it shows the server's built-in/default 500 error page. (I am assuming this, since the error occurs in .htaccess; it isn't processed and can't show the custom one.)

So my questions are: 1) Is it actually possible to generate a custom 500 page that will show up for users? 2) How can I test the response/error using non-.htaccess methods?

Yes, I have searched here on Server Fault. Yes, I tried to Google it as well. No, I haven't found anything on how to do a simple test. (Every time I found something causing a 500 response, it seemed to require me loading up lord-knows-what systems.)

Any help would be appreciated.

1 Answer 1

5

Within your virtual host conf (or httpd.conf/apache2.conf) you can use the ErrorDocument directive, as follows:

ErrorDocument 500 /errordocs/500error.php

It's inadvisable to do too much in your 500 error page, as you could hit the same error condition that caused the 500 response in the first place!

14
  • Thanks for the response Steve. I admit - I've been thinking much the same about problems repeating, such as if PHP goes down, then using PHP in the error file is a liability. So your suggestion would work fine for static - with little/no risk. The reason for wanting to use PHP in the error doc is to send a different response - a 503 is much more preferable than a 500 as far as Google goes.
    – Clueless
    Mar 16, 2011 at 12:15
  • Further - does anyone have any ideas on how to "test" the 500 error? I've looked around the Net, and not seen a single method for "testing" such an error. :(
    – Clueless
    Mar 16, 2011 at 12:16
  • 1
    @Clueless if PHP blows up to the point where it can't handle running a simple "custom error page" script you have bigger problems than your error page -- That Should Never Happen kind of problems. :-)
    – voretaq7
    Mar 16, 2011 at 15:40
  • 1
    @Steve Mayne True, but there's no good reason I can think of for your 500 error page to read from a database (and if there's a good reason I didn't think of you can certainly check for that kind of failure and degrade gracefully -- you can also do so in your original script, obviating the need for the error page in the first place ;)
    – voretaq7
    Mar 16, 2011 at 17:02
  • 1
    Update : Okay - the host has the server set so the CHMod of 666 results in an Error - and I've managed to test the 500 response. Indeed - my little php 500 Error page works fine (now giving a 503 response instead). Still leaves the issue of generally testing such a response - really am surprised no simple method exists (Will re-attempt the various Error setting computations, and see if I can get it to flag that way now I know it works).
    – Clueless
    Mar 19, 2011 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .