Php – LAMP: Custom 500 error page – is it actually possible

.htaccess500-errorapache-2.2PHP

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.

Best Answer

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!