I'm trying to enable basic debug output with WordPress for a plugin I'm developing. I managed to get some so far, but failed to redirect it to wp-content/debug.log
. I've been roughly following the guide by Douglas Neiner. Here's what I did:
I added this snippet of code to the end of wp-config.php
:
@ini_set ('display_errors', 0);
define ('WP_DEBUG', true);
define ('WP_DEBUG_DISPLAY', false);
define ('WP_DEBUG_LOG', true);
I manually created debug.log
file and made sure it's accessible by www-data
user (I'm running WordPress locally, on Ubuntu 12.04):
septi@norbert:~$ sudo su www-data -c 'ls -l /usr/share/wordpress/wp-content/debug.log'
-rw-rw-r-- 1 root www-data 0 Dec 9 22:12 /usr/share/wordpress/wp-content/debug.log
septi@norbert:~$ sudo su www-data -c 'ls -l /srv/www/localhost/wp-content/debug.log'
-rw-rw-r-- 1 root www-data 0 Dec 9 22:12 /srv/www/localhost/wp-content/debug.log
septi@norbert:~$ sudo su www-data -c 'echo i can write >> /usr/share/wordpress/wp-content/debug.log'
septi@norbert:~$
Added a few supposed debug output statement inside the plugin activation hook, as well as the intentional error:
include ('i fail wp');
register_activation_hook (__FILE__, 'hello_world_activate');
function hello_world_activate()
{
error_log ('I love debug output when it works!');
}
What I expect is an error message about the missing include file in debug.log
along with the "I love debug output when it works!" message, and nothing on the page. What I get is the missing include file on the page message and nothing in debug.log
. The debug output message is not fully lost, however. I found it in the /var/log/apache2/error.log
:
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning: include(i fail wp): failed to open stream: No such file or directory in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning: include(): Failed opening 'i fail wp' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] I love debug output when it works!, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning: include(i fail wp): failed to open stream: No such file or directory in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
[Sun Dec 09 22:58:18 2012] [error] [client 127.0.0.1] PHP Warning: include(): Failed opening 'i fail wp' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/wordpress/wp-content/plugins/helloworld2085/helloworld2085.php on line 28, referer: http://localhost/wp/wp-admin/plugins.php?deactivate=true&plugin_status=all&paged=1&s=
I suspect that the error_log()
function is not the right one to use to output to debug.log
, but I failed to find the right way. Oh, of course I could just hardcode the file path and append to it, but, you know...
I encountered the same problem with WordPress running in Apache 2.4 on Fedora 19. Output of error_log() was landing in /var/log/httpd/error_log instead of wp-content/debug.log. Httpd process had write permission (+775) to /var/www/html/wp-content directory, but it was unable to create the wp-content/debug.log file.
My wp-config.php debug setting was:
@ini_set(‘display_errors’,0);
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);
As it turned out, the real cause was SELinux. I made SELinux policy change and allowed httpd to write to wp-content with following commands. (Refer SELinux Troubleshooter to get the actual command for your installation)
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/wp-content'
restorecon -v '/var/www/html/wp-content'
After this debug messages start appearing in wp-content/debug.log.
the error_log() function writes to the web server's error log (e.g. /var/log/httpd/error_log); what you want is trigger_error().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With