IIS7.5上PHP站点的自定义500页面

I have a PHP (5.3) site running on a Windows 2008 R2 server (IIS7.5) & I'm trying to get a custom 500 page showing.

I've setup a test page, which generates a Fatal error - Call to undefined function functiondoesnotexist() in...

If I set error handling in the script to:

ini_set('display_errors', 1);
error_reporting(E_ALL);)

I do get to see the error on the page, BUT the page returns a 200 code.

If I turn off the error reporting, I just get a blank page (no source code at all), but the status is 500

However, it doesn't show the custome error page (500.php) - which is working when loaded directly.

Does anyone know what I'm missing? Thanks

To show a custom static file as a 500 error in a PHP site under IIS, after configuring the custom page through the IIS UI, you need to edit the web.config file and locate the httpErrors section. In this configuration node you must set the existingResponse property to "Replace" so that fastCGI uses the default IIS response instead of the fastCGI response that PHP uses.

Your web.config file section should look something like this:

<httpErrors existingResponse="Replace"> <remove statusCode="500" subStatusCode="-1" /> <error statusCode="500" prefixLanguageFilePath="" path="MyCustom500Errorpage.html" responseMode="File" /> </httpErrors>

Notice the property in the root node and the responseMode attribute set to File in the error node.

The file is located at the root folder. If you have any images, scripts or .css files used in it, make sure you're using paths related to the root folder (e.g.: "/Images/MyLogo.png" etc...).

HTH