Knowledge Base

Log File Analysis in Enhance

Log File Analysis in Enhance

Logs are like your website's diary - they record everything that happens, good and bad. Learning to read them is like gaining superpowers for troubleshooting!

Types of Log Files

Your hosting account generates several types of logs:

Log Type What It Records Location
Access Log Every visitor request /logs/access.log
Error Log Server and PHP errors /logs/error.log
PHP Error Log PHP-specific errors /logs/php_error.log
Mail Log Email sending activity /logs/mail.log
FTP Log FTP/SFTP connections /logs/ftp.log
Cron Log Scheduled task output /logs/cron.log

Accessing Log Files

Via Enhance Dashboard

  1. Navigate to Websites > Your Domain
  2. Click Logs or Log Files
  3. Select the log type you want to view
  4. Use the built-in viewer to browse

Log viewer interface

Via File Manager

  1. Open File Manager
  2. Navigate to the logs directory
  3. Click on a log file to view
  4. Use the search function if available

Via SSH

# View last 100 lines of error log
tail -100 ~/logs/error.log

# Watch error log in real-time
tail -f ~/logs/error.log

# Search for specific errors
grep "Fatal error" ~/logs/error.log

# View access log
tail -100 ~/logs/access.log

Understanding Access Logs

Access logs record every HTTP request to your website.

Log Format (Combined)

192.168.1.1 - - [27/Jan/2025:10:15:30 +0000] "GET /page.html HTTP/1.1" 200 5234 "https://google.com" "Mozilla/5.0..."
Part Meaning Example
IP Address Visitor's IP 192.168.1.1
Date/Time When request occurred 27/Jan/2025:10:15:30
Request Method and URL GET /page.html
Status Code Response status 200 (success)
Size Bytes sent 5234
Referrer Where they came from https://google.com
User Agent Browser/bot info Mozilla/5.0...

Common HTTP Status Codes

Code Meaning Action Needed
200 OK None - all good!
301 Permanent redirect Check if intentional
302 Temporary redirect Check if intentional
304 Not modified (cached) Good for performance
400 Bad request Check for malformed URLs
401 Unauthorized Login required
403 Forbidden Permission issue
404 Not found Fix broken links
500 Server error Check error logs!
502 Bad gateway Backend issue
503 Service unavailable Server overloaded
504 Gateway timeout Backend too slow

Analysing Access Logs

Find most requested pages:

awk '{print $7}' access.log | sort | uniq -c | sort -rn | head -20

Find IPs making most requests:

awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -20

Find 404 errors:

grep '" 404 ' access.log | awk '{print $7}' | sort | uniq -c | sort -rn

Find potential attacks:

grep -E "(wp-login|xmlrpc|admin)" access.log | awk '{print $1}' | sort | uniq -c | sort -rn

[SCREENSHOT: Terminal showing access log analysis commands and output]

Understanding Error Logs

Error logs are your best friend when things go wrong.

PHP Error Types

Type Severity Example
Fatal Error Critical - script stops Missing required file
Parse Error Critical - syntax issue Missing semicolon
Warning Important but continues Deprecated function
Notice Minor issue Undefined variable
Deprecated Future compatibility Old function usage

Example Error Log Entries

Fatal Error:

[27-Jan-2025 10:15:30 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/user/public_html/config.php:15

Warning:

[27-Jan-2025 10:16:45 UTC] PHP Warning: Division by zero in /home/user/public_html/calculate.php:23

Parse Error:

[27-Jan-2025 10:17:00 UTC] PHP Parse error: syntax error, unexpected '}' in /home/user/public_html/functions.php:156

Reading Error Messages

Every error tells you:

  1. When it happened (timestamp)
  2. What went wrong (error type and message)
  3. Where it occurred (file and line number)
[27-Jan-2025 10:15:30 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted in /home/user/public_html/wp-includes/class-wp-query.php on line 2456
  • When: 27-Jan-2025 10:15:30 UTC
  • What: Memory limit exceeded (256MB)
  • Where: class-wp-query.php, line 2456

Searching Error Logs

Find all fatal errors:

grep "Fatal error" ~/logs/error.log

Find errors from today:

grep "27-Jan-2025" ~/logs/error.log

Find errors in specific file:

grep "my-plugin.php" ~/logs/error.log

Count errors by type:

grep -oE "(Fatal error|Warning|Notice|Deprecated)" ~/logs/error.log | sort | uniq -c

[SCREENSHOT: Error log viewer showing various error types with timestamps]

WordPress-Specific Logging

Enabling WordPress Debug Log

Add to wp-config.php:

// Enable debugging
define('WP_DEBUG', true);

// Log errors instead of displaying
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

// Log database queries (use sparingly - generates large logs!)
define('SAVEQUERIES', true);

Debug log location: /wp-content/debug.log

Reading WordPress Debug Log

# View recent WordPress errors
tail -100 ~/public_html/wp-content/debug.log

# Find plugin errors
grep "plugins" ~/public_html/wp-content/debug.log

# Find database errors
grep -i "database\|mysql\|query" ~/public_html/wp-content/debug.log

Mail Logs

What Mail Logs Show

  • Emails sent from your website
  • Delivery status (sent, bounced, deferred)
  • SMTP errors
  • Spam rejections

Example Mail Log Entry

Jan 27 10:15:30 server postfix/smtp[12345]: ABC123: to=<user@example.com>, relay=mail.example.com[192.168.1.1]:25, status=sent (250 OK)

Common Mail Issues

"Relay access denied"

  • SMTP authentication failed
  • Check username and password

"Connection refused"

  • Mail server unreachable
  • Check firewall rules

"Mailbox full"

  • Recipient's mailbox is full
  • Not your problem (usually)

Log Rotation

Logs can grow enormous if left unchecked. Enhance typically handles rotation automatically:

  • Logs are rotated daily or weekly
  • Old logs are compressed (.gz)
  • Very old logs are deleted

Accessing Rotated Logs

# List all error logs including rotated
ls -la ~/logs/error.log*

# View compressed log
zcat ~/logs/error.log.1.gz

# Search in compressed logs
zgrep "Fatal error" ~/logs/error.log.*.gz

Real-Time Log Monitoring

Watching Logs Live

Via SSH:

# Watch error log in real-time
tail -f ~/logs/error.log

# Watch multiple logs
tail -f ~/logs/error.log ~/logs/access.log

# Watch with highlighting (if `ccze` is available)
tail -f ~/logs/error.log | ccze

Via Enhance Dashboard:

  1. Go to Logs
  2. Enable "Live" or "Real-time" mode
  3. Watch entries appear as they happen

[SCREENSHOT: Real-time log viewer with live entries appearing]

Common Issues and Their Log Signatures

Site Down - 500 Error

Look in error logs for:

PHP Fatal error: ...
Segmentation fault
Out of memory

Site Slow

Check access logs for:

  • Very long response times
  • Many requests from same IP (attack?)
  • Heavy resources being requested repeatedly

Hacked Website

Warning signs in logs:

# Suspicious file access
GET /wp-content/uploads/evil.php
POST /xmlrpc.php (many requests)
GET /wp-admin/ from unusual IPs

# Encoded/obfuscated requests
eval(base64_decode...
\x encoded strings

Email Not Sending

Check mail logs for:

status=bounced
status=deferred
relay access denied
connection refused

Log Analysis Tools

Command-Line Tools

  • grep - Search for patterns
  • awk - Extract and process fields
  • sort - Sort results
  • uniq - Count unique entries
  • tail/head - View portions of files
  • wc - Count lines/words

Online Analysis Tools

Upload your logs (anonymised if needed) to:

  • GoAccess - Visual log analyser
  • AWStats - Statistical analysis
  • Webalizer - Traffic reports

Setting Up GoAccess (if available)

# Generate HTML report
goaccess ~/logs/access.log -o report.html --log-format=COMBINED

# Real-time terminal view
goaccess ~/logs/access.log --log-format=COMBINED

[SCREENSHOT: GoAccess report showing visitor statistics and top pages]

Best Practices

  1. Check logs regularly - Don't wait for problems
  2. Set up alerts - Be notified of critical errors
  3. Keep logs for 30+ days - For troubleshooting historical issues
  4. Secure your logs - They contain sensitive information
  5. Learn basic grep/awk - Makes analysis much faster
  6. Document patterns - Note what "normal" looks like

Next Steps: Managing domains? Check out our Domain Management Guide.

Please rate this article to help us improve our Knowledge Base.

0 0