WordPress Debugging: Transitioning from WP_DEBUG_DISPLAY to WP_DEBUG_LOG for Production
0 reputation · 04 Sept 2022, 15:03 UTC
0 reputation · 04 Sept 2022, 15:03 UTC
When managing WordPress deployments, the transition from a development environment to a production server requires a change in how PHP errors are handled. While WP_DEBUG is essential for identifying fatal errors or the "White Screen of Death," displaying these errors directly in the browser via WP_DEBUG_DISPLAY creates a security risk by exposing absolute file paths and server configurations.
The goal is to maintain full diagnostic visibility without compromising the front-end user experience or security. This involves shifting the error output mechanism to a server-side file using WP_DEBUG_LOG, which captures errors in /wp-content/debug.log.
There is uncertainty regarding how server-level php.ini settings or hosting provider overrides may conflict with these wp-config.php constants, potentially preventing the log file from being created even when the constants are set to true.
display_errors = Off setting in php.ini override the WP_DEBUG_DISPLAY constant?WP_DEBUG_LOG fail to write to the filesystem despite being enabled in the configuration?A server-level display_errors = Off in php.ini does not automatically override WP_DEBUG_DISPLAY. WordPress applies its debug constants at runtime through ini_set() inside wp_debug_mode(), so the constant typically wins unless the host has locked the directive with php_admin_flag or php_admin_value.
WP_DEBUG_LOG fails to write in several specific scenarios even when the constant is set to true:
WP_DEBUG is false or absent—WP_DEBUG_LOG is ignored entirely.wp-content/debug.log.open_basedir restrictions block the wp-content path.log_errors is disabled or locked by the host.Confirmed behavior: WP_DEBUG_LOG=true directs PHP errors to wp-content/debug.log relative to the WordPress root. WP_DEBUG_DISPLAY=false suppresses on-screen output while still allowing the log file to capture entries.
Likely explanation: because wp-config.php constants are applied at runtime rather than replacing php.ini, they remain subject to PHP's override hierarchy and filesystem checks. If a managed host enforces error-handling directives at the pool or server level, the constants may be silently ignored.
wp-config.php contains WP_DEBUG true, WP_DEBUG_DISPLAY false, and WP_DEBUG_LOG true.phpinfo() or ini_get('display_errors') / ini_get('log_errors') to see whether the runtime values match expectations.ls -l wp-content/debug.log
If the file does not exist, check directory permissions on wp-content/.wp-content/debug.log.open_basedir, log_errors, and available disk space.Because debug.log can expose absolute paths and plugin internals, block direct HTTP access to it via server rules. On high-traffic production sites, monitor disk usage—continuous error logging can fill storage and degrade performance.
Are display_errors or log_errors locked by your host via php_admin_flag or php_admin_value? If they are locked, wp-config.php constants cannot override them and you must ask the host to adjust the pool configuration. If they are not locked, the issue is almost certainly filesystem permissions or an open_basedir restriction.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.