WP_DEBUG is a WordPress constant that enables debugging mode, allowing developers to troubleshoot issues by logging errors, warnings, and notices. This guide explains how to check WP_DEBUG logs using various methods.
Prerequisites
- Access to your WordPress installation (via hosting control panel, FTP, or SSH).
- Basic understanding of WordPress configuration files.
- WP_DEBUG enabled in your
wp-config.php
file. To enable it, add or modify the following lines:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false ); // Prevents errors from displaying on the site
Method 1: Checking Debug Logs via File Access
WordPress stores debug logs in a file when WP_DEBUG_LOG
is enabled. By default, the log file is located at wp-content/debug.log
, but you can specify a custom location for better organization or security.
Steps:
- Configure Log Location:
- For the default log location, ensure
WP_DEBUG_LOG
is set totrue
inwp-config.php
. - For a custom log location, add or edit the following line in
wp-config.php
to specify a path:
define( 'WP_DEBUG_LOG', '/path/to/custom/debug.log' );
- Ensure the directory is writable by the web server (e.g., set permissions to
664
or666
for the file and755
for the directory).
- Access Your WordPress Files:
- Use an FTP client (e.g., FileZilla) or your hosting file manager to access your WordPress installation.
- Alternatively, use SSH to connect to your server for faster access.
- Locate the Debug Log:
- Navigate to the
wp-content
directory for the default log (wp-content/debug.log
) or to your custom path (e.g.,/path/to/custom/debug.log
). - If the log file doesn’t exist, ensure
WP_DEBUG_LOG
is correctly configured and trigger an action on your site (e.g., refreshing a page) to generate logs.
- View the Log:
- Download the log file and open it with a text editor (e.g., Notepad++, VS Code).
- Alternatively, use SSH to view the file directly with a command like
cat wp-content/debug.log
orcat /path/to/custom/debug.log
.
- Interpret the Logs:
- Logs include timestamps, error types (e.g.,
PHP Warning
,PHP Notice
), and details about the issue, including the file and line number causing the error.
Notes:
- Custom log locations are useful when
wp-content
is not writable or for organizing logs in a secure directory. - Ensure custom paths are not publicly accessible to prevent exposing sensitive information.
- If the log file is large, use tools like
grep
(e.g.,grep "PHP Error" wp-content/debug.log
) to filter specific errors. - Regularly clear or rotate the log file to prevent it from growing too large.
Method 2: Using a Debugging Plugin
Several WordPress plugins simplify the process of viewing debug logs without direct file access.
Recommended Plugins:
- Debug Log Manager: A dedicated plugin for enabling, managing and viewing debug logs.
- Query Monitor: Displays debug information, including errors, directly in the WordPress admin panel.
- Debug Bar: Adds a debug menu to the admin bar, showing logs and other debugging data.
Steps:
- Install a Plugin:
- Go to Plugins > Add New in your WordPress admin panel.
- Search for and install your chosen debugging plugin (e.g., Debug Log Manager).
- Activate the plugin.
- Access Debug Logs:
- For Debug Log Manager, navigate to Tools > Debug Log Manager in the WordPress admin panel to view, filter, or download the debug log. The plugin also allows you to clear logs or configure log settings.
- For Query Monitor, navigate to the Query Monitor menu in the admin bar to view errors and logs.
- For Debug Bar, click the Debug Bar in the admin bar and explore the log section.
Notes:
- Plugins may require
WP_DEBUG
andWP_DEBUG_LOG
to be enabled. - Debug Log Manager offers additional features like log filtering by error type and log file size management.
Method 3: Real-Time Debugging with a Terminal
For advanced users, you can monitor debug logs in real-time using SSH and terminal commands.
Steps:
- Access Your Server via SSH:
- Connect to your server using an SSH client (e.g., PuTTY or terminal).
- Monitor the Debug Log:
- Run the following command to watch the log file in real-time:
tail -f wp-content/debug.log
- For a custom log location, use:
tail -f /path/to/custom/debug.log
- The
-f
flag ensures new log entries are displayed as they are written.
- Trigger Actions:
- Perform actions on your WordPress site (e.g., refresh a page, submit a form) to generate log entries.
- Observe the terminal for immediate feedback.
Notes:
- Use
Ctrl+C
to stop monitoring. - Combine with
grep
for filtering (e.g.,tail -f wp-content/debug.log | grep "PHP Error"
).
Method 4: Using Error Log Integrations
Some hosting providers or server setups allow you to integrate WordPress debug logs with server error logs or third-party monitoring tools.
Steps:
- Check Hosting Control Panel:
- Log in to your hosting control panel.
- Look for an Error Logs or Logs section.
- If
WP_DEBUG_LOG
is configured to write to a server-accessible file, errors may appear here.
- Integrate with Third-Party Tools:
- Use tools like New Relic, Sentry, or Loggly to collect and analyze WordPress debug logs.
- Configure these tools via plugins or by directing
WP_DEBUG_LOG
output to their APIs.
Notes:
- This method requires additional setup and may involve costs for third-party services.
- Ensure your hosting environment supports custom log integrations.
Best Practices
- Disable Debugging on Live Sites: Set
WP_DEBUG
tofalse
on production sites to prevent exposing sensitive information. - Secure Log Files: Ensure
debug.log
is not publicly accessible (e.g., adddeny from all
to.htaccess
for the log file). - Regular Maintenance: Periodically clear or archive logs to manage disk space.
- Test in Staging: Replicate issues in a staging environment to avoid disrupting live sites.
Troubleshooting Common Issues
No debug.log
File:
- Verify
WP_DEBUG
andWP_DEBUG_LOG
are set totrue
inwp-config.php
. - Check if the
wp-content
directory or custom log directory is writable (permissions should be755
for directories and664
or666
for files).
Logs Are Empty:
- Ensure actions triggering errors are performed after enabling debugging.
- Check for syntax errors in
wp-config.php
that might prevent logging.
Large Log Files:
- Use log rotation tools or plugins like Debug Log Manager to manage file size.
- Filter logs with tools like
grep
to focus on relevant entries.
By using these methods, you can effectively monitor and troubleshoot issues in your WordPress site using WP_DEBUG logs. Choose the method that best fits your technical expertise and hosting environment.