When working with PHP 5.2.5 on IIS7, developers often encounter generic 500 errors instead of meaningful PHP error messages. This default behavior might be suitable for production servers, but it's absolutely counterproductive during development.
First, let's ensure your php.ini is properly configured. Add or modify these settings:
display_errors = On
display_startup_errors = On
error_reporting = E_ALL
log_errors = On
error_log = "C:\php_errors.log"
The real solution requires both PHP and IIS configuration. For IIS7, we need to modify the FastCGI settings:
<configuration>
<system.webServer>
<fastCgi>
<application fullPath="C:\PHP\php-cgi.exe">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHP_ERROR_LOG" value="C:\php_errors.log" />
<environmentVariable name="PHPRC" value="C:\PHP" />
</environmentVariables>
</application>
</fastCgi>
</system.webServer>
</configuration>
Create a test PHP file with intentional errors to verify your setup:
<?php
// Force some errors
echo $undefined_variable;
include('nonexistent_file.php');
trigger_error("Test error", E_USER_WARNING);
?>
- Permissions issues: Ensure IIS_IUSRS has write access to your error log directory
- Conflicting settings: Check if any .htaccess or web.config overrides exist
- Multiple php.ini files: Verify which php.ini is actually being loaded using phpinfo()
For more control, implement a custom error handler:
<?php
function customErrorHandler($errno, $errstr, $errfile, $errline) {
error_log("[$errno] $errstr in $errfile on line $errline", 3, "C:\custom_errors.log");
echo "<div style='color:red'>Error: [$errno] $errstr</div>";
return true;
}
set_error_handler("customErrorHandler");
?>
When running PHP 5.2.5+ on IIS7, you might encounter the frustrating scenario where PHP errors generate generic 500 errors instead of meaningful diagnostic messages. This occurs because IIS7's default FastCGI configuration intercepts PHP errors before they reach the client.
First, ensure these settings in your php.ini file:
display_errors = On
display_startup_errors = On
error_reporting = E_ALL
log_errors = On
error_log = "C:\php_errors\php_errors.log"
Modify the FastCGI configuration in applicationHost.config (typically located in C:\Windows\System32\inetsrv\config):
<fastCgi>
<application fullPath="C:\PHP\php-cgi.exe" activityTimeout="600"
requestTimeout="600" instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\PHP" />
</environmentVariables>
</application>
</fastCgi>
For error logging to work properly:
- Grant IIS_IUSRS modify permissions to your PHP error log directory
- Ensure the application pool identity has write access to the log file
If errors still don't appear:
// Test script to verify configuration
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
trigger_error("Test error message", E_USER_WARNING);
?>
For custom error handling in development environments:
// Custom error handler example
function devErrorHandler($errno, $errstr, $errfile, $errline) {
echo "<div style='background:#ffeeee;padding:10px;border:1px solid red'>";
echo "<b>PHP Error [$errno]</b>: $errstr in $errfile on line $errline";
echo "</div>";
}
set_error_handler("devErrorHandler");