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.

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

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!

link|improve this answer
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 '11 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 '11 at 12:16
@Clueless - "anyone have any ideas on how to "test" the 500 error?" telnet localhost 80 + (Enter) + HEAD /path/to/500/error/page HTTP/1.1 + (Enter) + Host: yourhost.com + (Enter) + (Enter) – danlefree Mar 16 '11 at 13:35
@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 '11 at 15:40
@voretaq7 - you could feasibly have a database failure which leads to the original 500 - and if your 500-handling php script attempts to read from the same database... well, you get the idea. – Steve Mayne Mar 16 '11 at 16:54
show 9 more comments
feedback

Your Answer

 
or
required, but never shown

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