I have a production server running commercial software that utilizes deprecated functionality. We already disabled error outputs in php.ini --
display_errors = Off
log_errors = On
When PHP runs as an Apache module, you can access/change any configuration setting available in
php.ini using directives in Apache configuration files. Those directives are...
The difference between the
php_admin_* versions is the key to this issue. Values set using
php_admin_flag can only be set in Apache global and VirtualHost configs; they are not overrideable by .htaccess or ini.set().
error_reporting() function is equivalent to an
ini_set() call, and falls under the same rules.
So I went into the virtualhost configuration for the site in question, and added the following lines...
php_admin_value error_reporting 22527 php_admin_value error_log /custom/log/path/php_errors.log php_admin_flag log_errors On php_admin_flag display_errors Off
The first line is the bitwise value for
error_reporting = E_ALL & ~E_DEPRECATED. I retrieved this value by creating a simple script:
ini_set("error_reporting", E_ALL & ~E_DEPRECATED); echo ini_get("error_reporting");
If you want to ignore system notices along with deprecation alerts --
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE -- the bitwise value is
The second line sends all PHP errors to a custom log. By default PHP will use the
syslog value, usually
/var/log/apache2/error.log or something similar.
The third line enables file logging.
Last one turns off on-page error display.
Again, the priority and order of operations is key here. These values supersede those defined in
php.ini, and at the same time cannot be overridden by other changes within the application or in
More details on changing configuration values outside php.ini can be found in the PHP documentation.