Back to Shared Hosting Documentation

    Log Files Management

    Access and analyze server logs for troubleshooting and monitoring.

    What are Log Files?

    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:

    • Access Logs: All requests to your website
    • Error Logs: PHP errors, warnings, notices
    • Email Logs: Email sending/receiving activity
    • FTP Logs: FTP connection attempts
    • cPanel Access Logs: cPanel login attempts

    Accessing Log Files in cPanel

    Method 1: Raw Access Logs

    1. Log in to cPanel
    2. Navigate to "Metrics" section
    3. Click "Raw Access"
    4. See list of available log files
    5. Click to download or view in browser

    Method 2: Error Logs

    1. In cPanel → Metrics
    2. Click "Errors"
    3. View recent 300 errors
    4. See timestamp, error type, and details

    Method 3: File Manager

    1. Go to File Manager
    2. Navigate to your domain's folder (usually public_html)
    3. Look for error_log file
    4. Right-click and "View" or "Download"

    Understanding Access Logs

    Access 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:

    • 192.168.1.1: Visitor IP address
    • [24/Oct/2025:10:15:30 +0000]: Timestamp
    • "GET /page.html HTTP/1.1": Request method and URL
    • 200: HTTP status code (success)
    • 1234: Bytes transferred
    • "https://google.com/": Referrer
    • "Mozilla/5.0...": User agent (browser info)

    Common HTTP Status Codes

    Success (2xx)

    • • 200: Success
    • • 301: Permanent redirect
    • • 302: Temporary redirect

    Client Error (4xx)

    • • 400: Bad request
    • • 403: Forbidden
    • • 404: Not found

    Server Error (5xx)

    • • 500: Internal server error
    • • 502: Bad gateway
    • • 503: Service unavailable

    Understanding Error Logs

    Error Log Format:

    [24-Oct-2025 10:15:30 UTC] PHP Warning: Division by zero in /home/user/public_html/script.php on line 42

    PHP 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.

    Common Error Messages

    Memory Exhausted:

    Fatal error: Allowed memory size of 134217728 bytes exhausted

    Solution: Increase PHP memory limit or optimize code

    Maximum Execution Time:

    Fatal error: Maximum execution time of 30 seconds exceeded

    Solution: Increase max_execution_time or optimize script

    Analyzing Log Files

    Command Line Analysis (SSH)

    # 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 -10

    Online Log Analyzers

    • GoAccess: Real-time log analyzer, terminal or HTML output
    • AWStats: Available in cPanel, graphical statistics
    • Webalizer: Another cPanel option, simple visual reports

    Common Use Cases for Log Files

    Troubleshooting Errors

    • • Identify white screen of death causes
    • • Find PHP warnings and notices
    • • Locate database connection errors
    • • Debug plugin conflicts

    Security Monitoring

    • • Detect brute force login attempts
    • • Identify suspicious IP addresses
    • • Monitor for hacking attempts
    • • Track unauthorized access

    Performance Analysis

    • • Find slow-loading pages
    • • Identify resource-heavy requests
    • • Detect bot traffic
    • • Analyze peak traffic times

    SEO and Marketing

    • • Track search engine crawlers
    • • Find broken links (404 errors)
    • • Analyze referrer traffic
    • • Identify popular content

    Managing Log File Size

    Large 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 file

    Archive Old Logs:

    # Compress old logs
    gzip access_log.1
    tar -czf logs-archive-2025-10.tar.gz *.gz

    WordPress Error Logging

    Enable 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.

    Security Best Practices

    Protect Log Files:

    # Add to .htaccess
    <Files error_log>
        Order allow,deny
        Deny from all
    </Files>

    What to Look For:

    • • Repeated failed login attempts
    • • Unusual traffic spikes
    • • Access to admin areas from unknown IPs
    • • Requests for suspicious files (*.php.suspected)
    • • SQL injection attempts in URLs

    Best Practices

    • • Regular checks: Review logs at least weekly
    • • Archive important logs for history
    • • Monitor disk space usage
    • • Fix errors promptly
    • • Use log rotation
    • • Secure log files from public access
    • • Set up alerts for critical errors
    • • Backup before deleting logs