WP_DEBUG_LOG Enabled but wp-content/debug.log Missing on Production Hosts
0 reputation · 08 Apr 2024, 09:41 UTC
0 reputation · 08 Apr 2024, 09:41 UTC
WP_DEBUG_LOG is documented to direct debug output to wp-content/debug.log, but the constant itself does not create that file. On a local development machine the directory is typically writable by the PHP process, so the log appears once an error or notice is triggered. On a production host with restrictive ownership or permissions, the same configuration can yield no log at all, and the failure is silent.
This behavior is consistent across WordPress 6.x and 7.x; the file-creation logic has not changed. The determining factor is whether the target path already exists and is writable by the web server user, which can be inspected with PHP's is_writable() rather than assumed.
The unresolved design question is where responsibility should sit.
wp-content/debug.log when WP_DEBUG_LOG is enabled, or require an administrator to pre-create it?34775 reputation · 08 Apr 2024, 11:35 UTC
WP_DEBUG_LOG does not create wp-content/debug.log. It only tells WordPress to pass that path to PHP's error_log() function. The file is created lazily by the PHP runtime only when an error or notice occurs and only if the wp-content directory is writable by the web-server user (e.g., www-data, nginx, php-fpm). On production hosts where wp-content is owned by a deploy user with 0755 permissions, the PHP process cannot write there, error_log() fails silently, and no log file appears.
wp-includes/load.php) checks WP_DEBUG_LOG but never calls mkdir(), touch(), or is_writable() on the log path. This behavior is identical in WordPress 6.x and 7.x.WP_DEBUG_LOG is set to a custom absolute path (e.g., /var/log/wp-debug.log), the same writability rule applies to that directory.debug.log with WP_DEBUG_LOG enabled is almost always a filesystem-permission issue, not a configuration syntax error.Your production host likely runs PHP-FPM under a different user than the one that owns wp-content. The directory permissions (0755) allow the owner to write but not the PHP-FPM user. When WordPress triggers a notice or error, PHP's error_log() attempts to open wp-content/debug.log for appending, receives EACCES (Permission denied), and discards the message without raising a PHP warning.
sudo -u www-data php -r \"var_dump(is_writable('/full/path/to/wp-content'));\"
Replace www-data with your PHP-FPM user (check ps aux | grep php-fpm).
sudo touch /full/path/to/wp-content/debug.log
sudo chown www-data:www-data /full/path/to/wp-content/debug.log
sudo chmod 640 /full/path/to/wp-content/debug.log
sudo mkdir -p /var/log/wordpress
sudo chown www-data:www-data /var/log/wordpress
sudo chmod 750 /var/log/wordpress
Then in wp-config.php:
define('WP_DEBUG_LOG', '/var/log/wordpress/debug.log');
<?php error_log('WP_DEBUG_LOG test ' . date('c')); ?>
Place in a mu-plugin or theme functions.php, load any page, then check the log file.
A web-accessible debug.log can expose stack traces, plugin paths, and database credentials. Always either:
.htaccess (Deny from all) or Nginx (location ~ /debug\\.log { deny all; }).What user runs your PHP-FPM pool? (Run ps aux | grep php-fpm | head -1 | awk '{print $1}'.) The fix changes if the PHP user differs from www-data or if your host uses a containerized setup where the filesystem is read-only.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.