Search code examples
phpwordpresserror-loggingerror-log

Why are my PHP errors appearing in several different files?


I was trying to debug a custom WordPress PHP file in /public_html/wp-content/plugins/myfolder/inc but for some reason the errors weren't appearing in the usual public_html/php_errorlog file.

After some searching, I found that the file was instead writing all of its errors, exception, warnings, and error_log output to public_html/wp-admin/php_errorlog instead.

I also noticed a third php_errorlog file in wp-includes, though nothing had written to it in over a month.

What could be causing it to write to different locations, and how can I make it only write to public_html/php_errorlog?

Edit: Upon further testing with getcwd(), it appears that it always chooses to log to a file in the current directory. So I now have a rough idea of what's going on, but I need to know what file or setting is responsible for that so that I can change it.


Solution

  • This is actually a "perk" of some webhosting services (I found this behavior mostly on cheap shared ones).

    The error log is being stored in the directory in which the error occurred. The setting responsible for it is error_log = error_log in php.ini

    Source: https://www.inmotionhosting.com/support/website/php-troubleshooting/troubleshoot-php-errors