Access and analyze server logs for troubleshooting and monitoring.
Log files record events and activities on your server. They're essential for troubleshooting errors, monitoring security, analyzing traffic, and understanding how your website performs.
Types of Logs:
error_log fileAccess Log Format:
192.168.1.1 - - [24/Oct/2025:10:15:30 +0000] "GET /page.html HTTP/1.1" 200 1234 "https://google.com/" "Mozilla/5.0..."Log Entry Breakdown:
Success (2xx)
Client Error (4xx)
Server Error (5xx)
Error Log Format:
[24-Oct-2025 10:15:30 UTC] PHP Warning: Division by zero in /home/user/public_html/script.php on line 42PHP Error Types:
Fatal Error
Script execution stopped. Critical issues that must be fixed.
Warning
Non-fatal error. Script continues but should be addressed.
Notice
Minor issue. Often undefined variables or indices.
Parse Error
Syntax error. Code doesn't follow PHP syntax.
Memory Exhausted:
Fatal error: Allowed memory size of 134217728 bytes exhaustedSolution: Increase PHP memory limit or optimize code
Maximum Execution Time:
Fatal error: Maximum execution time of 30 seconds exceededSolution: Increase max_execution_time or optimize script
# View last 100 lines
tail -n 100 error_log
# Follow log in real-time
tail -f error_log
# Search for specific error
grep "Fatal error" error_log
# Count occurrences
grep -c "404" access_log
# Find most accessed pages
awk '{print $7}' access_log | sort | uniq -c | sort -rn | head -10
# Find most common IP addresses
awk '{print $1}' access_log | sort | uniq -c | sort -rn | head -10Large logs consume disk space and count toward inode limits.
Clear Error Log:
# Via SSH
> error_log
# Or via File Manager
Delete or empty error_log fileArchive Old Logs:
# Compress old logs
gzip access_log.1
tar -czf logs-archive-2025-10.tar.gz *.gzEnable WordPress Debug Mode:
Edit wp-config.php:
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to /wp-content/debug.log
define( 'WP_DEBUG_LOG', true );
// Disable display of errors on site
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );Important: Disable WP_DEBUG on live sites! Only use for development/troubleshooting.
Protect Log Files:
# Add to .htaccess
<Files error_log>
Order allow,deny
Deny from all
</Files>What to Look For: