500 Internal Server Error with PHP FastCGI on Windows

Running PHP via the FastCGI module on Windows servers means that PHP is executed extremely quickly. However one of the problems is that instead of outputting errors the server simply returns a 500 Server Error or Internal Server Error. This can be unhelpful as you need to see the error message to debug.

Firstly you need to turn off custom errors. This can sometimes be done via your control panel. Alternatively create a web.config file (or add to an existing) with the following

<?xml version="1.0" encoding="utf-8" ?>
<customErrors mode="Off"/>
However even with customErrors disabled you still receive a 500 Internal Server Error. The reason this happens is because the PHP handler does not pass the error to IIS. To change this behaviour you need to make changes on the server (If you have shared hosting this is not possible).

Log in to your Windows server and then execute the following command line

c:windowssystem32inetsrvappcmd.exe set config "{sitename}" -section:system.webServer/httpErrors
/existingResponse:"PassThrough" /commit:apphost
What this does is tells IIS to passthrough errors from the relevant handler. Be sure to replace {sitename}with the actual site name inIIS.

Related Articles