Checking wp debug.log files
Why debug.log Files Matter
- Performance impact: Large log files can eat up disk space and slow down file operations.
- Backup bloat: If your backups include
debug.log, they can become unnecessarily large. - Security risk: Debug logs may contain sensitive paths, plugin names, or even database queries. If exposed publicly, attackers could use this information.
- Maintenance signal: A growing
debug.logoften indicates unresolved errors or misconfigured plugins/themes.
Finding the Biggest debug.log Files
On a Linux server, you can use the find command to locate and measure log files. Here are two approaches:
1. Broad Search Across All Home Directories
find /home/ -type f -name "debug.log" -exec du -h {} + | sort -hr | head -20
- What it does: Searches every user’s home directory for
debug.logfiles. - Why use it: Useful if you’re not sure where WordPress is installed or if you manage multiple accounts.
- Output: Shows the top 20 largest
debug.logfiles, sorted by size.
2. Targeted Search in WordPress wp-content Folders
find /home/*/public_html/wp-content/ -type f -name "debug.log" -exec du -h {} + | sort -hr | head -20
- What it does: Focuses only on the typical WordPress
wp-contentdirectory under each user’spublic_html. - Why use it: Faster and more precise if you know all your WordPress installs follow the standard cPanel-style layout.
- Caveat: Not all WordPress sites use
/public_html/wp-content/. Some may be installed in subdirectories (/home/user/blog/wp-content/) or custom paths. Adjust the command accordingly.
What to Do After Finding Large Logs
- Inspect the contents: Look for recurring errors. They may point to a misbehaving plugin, theme, or custom code.
- Fix the root cause: Don’t just delete the log — resolve the error generating it.
- Truncate safely: If the file is huge, you can clear it without deleting:
truncate -s 0 /path/to/debug.log
- Disable debugging in production: In
wp-config.php, set:
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
Debugging should only be enabled temporarily when troubleshooting.
Security Considerations
- Never expose debug.log publicly: Ensure your server configuration prevents direct access to
wp-content/debug.log. - Monitor regularly: Set up a cron job to check for large logs and alert you.
- Audit plugins/themes: Frequent errors may indicate outdated or insecure code.
- Limit error detail: In production, avoid verbose error logging that could leak sensitive paths or queries.
Conclusion
Managing debug.log files is more than just housekeeping — it’s a critical part of WordPress maintenance and security. By regularly scanning for oversized logs using commands like:
Broad search:
find /home/ -type f -name "debug.log" -exec du -h {} + | sort -hr | head -20
Targeted search:
find /home/*/public_html/wp-content/ -type f -name "debug.log" -exec du -h {} + | sort -hr | head -20
…you can keep your server lean, your backups efficient, and your sites secure.