After upgrading from Debian Lenny to Squeeze with PHP 5.3.2-2 and Apache 2.2.16, you're seeing HTML-formatted deprecation warnings flooding your /var/log/apache2/errors.log:
Warning: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0
Warning: Directive 'register_globals' is deprecated in PHP 5.3 and greater in Unknown on line 0
PHP 5.3 introduced strict deprecation warnings for legacy features like magic_quotes_gpc and register_globals. These warnings are emitted during PHP startup (hence "Unknown" file and line 0) and bypass normal error handling due to their early execution timing.
1. Proper Error Reporting Configuration
While you've set error_reporting to exclude E_DEPRECATED, these particular warnings still appear because:
# Add this to php.ini or .htaccess
log_errors = On
error_log = /var/log/php_errors.log
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE
2. Apache-Specific Error Filtering
Create a custom error log format in Apache to filter HTML tags:
# In httpd.conf or apache2.conf
ErrorLogFormat "[%t] [%l] %M"
CustomLog /var/log/apache2/clean_errors.log "%t %h \"%r\" %>s %b"
3. PHP INI Workaround
For systems where you can't immediately update legacy code:
; In php.ini
html_errors = Off
ignore_repeated_errors = On
ignore_repeated_source = On
For virtual hosts needing special handling:
<VirtualHost *:80>
ServerName legacy.example.com
php_admin_value error_log "/var/log/php_legacy_errors.log"
php_admin_value html_errors "Off"
</VirtualHost>
While the above are workarounds, the real fix involves:
- Migrating away from deprecated functions
- Implementing proper input filtering to replace magic_quotes
- Using $_GET/$_POST superglobals instead of register_globals
For legacy apps that can't be immediately updated, consider wrapping deprecated code:
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
@ini_set('magic_quotes_gpc', 0);
@ini_set('register_globals', 0);
}
After upgrading from Debian Lenny to Squeeze, many developers encounter these persistent warnings in Apache's error log:
Warning: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater
Warning: Directive 'register_globals' is deprecated in PHP 5.3 and greater
What's particularly annoying is that these HTML-formatted messages pollute your system logs, appearing on every page load across all virtual hosts.
PHP 5.3 marked several legacy features as deprecated, but they still generate warnings even when:
- You're running legacy code that requires these features
- You've explicitly set
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED - The warnings appear in system logs rather than just browser output
Here are three approaches to silence these warnings while maintaining legacy functionality:
1. Modify php.ini for System-Wide Fix
Add these lines to your php.ini:
; Disable deprecation warnings at engine level
engine_errors = Off
; Alternative: Custom error log for deprecation warnings
error_log = /var/log/php_deprecated.log
log_errors_max_len = 0
2. Apache-Specific Configuration
Create or modify your VirtualHost configuration:
# Other directives...
php_admin_value engine_errors "0"
php_admin_value error_log "/var/log/php_errors.log"
3. PHP Runtime Control
For cases where you can't modify server config, add this to your bootstrap file:
// Disable deprecation warnings only
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
// Alternative: Set custom error handler
set_error_handler(function($errno, $errstr) {
if (strpos($errstr, 'deprecated') === false) {
return false; // Let standard handler deal with it
}
return true; // Silently ignore deprecation warnings
}, E_ALL);
While suppressing these warnings solves the logging issue, remember:
- These features will be completely removed in future PHP versions
- magic_quotes_gpc can be replaced with proper input filtering
- register_globals should be replaced with explicit variable initialization
- Consider running your code through PHP7CC for compatibility checking