Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable all php warning in server log file wordpress

I have any issues my server log file reached 9 GB with in one month due to warnings of word press. I want to stop all the warnings generated by wordpress in server error log.

How can I do this?

like image 299
buttjee Avatar asked Sep 19 '25 14:09

buttjee


1 Answers

The problem with WordPress, or PHP in general, is that by default, the error_reporting setting can be arbitrarily overriden at run-time. In WordPress you will find that many plugins, themes and even WP Core set error_reporting themselves.

So even if you override it in your wp-config.php it won't do any good.

When using PHP < 8.0, if you want to keep your logs free of non-errors, the only way I have found is use a combination of these two directives in php.ini:

error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
disable_functions = error_reporting

To restrict to a certain path and disable all error reporting:

[PATH=/var/www/site]
error_reporting = 0
disable_functions = error_reporting

If you don't exclude E_WARNING, you will get warnings generated by the fact that the error_reporting function is disabled.

Note: disable_functions accepts a comma separate list of function names.

If you are using php-fpm you can set it like this:

php_admin_value[disable_functions] = error_reporting

When using PHP >= 8.0, disabling the error_reporting function generates a fatal error. WordPress Core has partially fixed this but there are other places in the code, as well as in themes/plugins which still expect the error_reporting function to be enabled. This means the only safe way to disable this function when running WordPress is to also define a dummy function in wp-config.php, e.g.

if ( !function_exists('error_reporting')) {
  function error_reporting() {}
}

Currently the error_reporting function is also used in wp-admin/load-styles.php, which does not include wp-config.php, so you'll have to add a patch or your own include for this file also.

If you don't have control over php.ini or the php-fpm config then you're out of luck, unfortunately.

like image 82
Joe Niland Avatar answered Sep 22 '25 04:09

Joe Niland