πŸ’‘ CloudPicked is an independent author. We receive affiliate commission from some providers Β· Learn more

Complete Guide to Server Log Analysis for Hosting & VPS

Server Log Analysis Guide

Server logs are permanent records of all activities on your hosting server. From HTTP requests by visitors, to PHP errors, to potential security threats β€” everything is logged. When you host a website on shared hosting or VPS, understanding how to read and analyze these logs is essential for debugging errors, monitoring performance, detecting hacking attempts, and ensuring your site runs smoothly. In this complete guide, we'll teach you everything you need to know about server log analysis.

What Are Log Files? What Does Hosting Log?

Log files are text files that record events happening on your server, each entry timestamped for precision. Every hosting provider and VPS keeps multiple types of logs:

By learning to read logs, you can diagnose problems instantly instead of guessing. When your website goes down, the error log often contains the exact answer. This is why experienced developers check logs first.

Log File Locations on Linux Server & SSH Access

If your hosting provider offers a graphical file manager (cPanel or DirectAdmin), you can download logs easily. But if you need SSH access to logs, you'll need to know their standard locations on Linux:

# Apache Access Log
/var/log/apache2/access.log
/var/log/httpd/access_log

# Apache Error Log
/var/log/apache2/error.log
/var/log/httpd/error_log

# Nginx Access Log
/var/log/nginx/access.log

# Nginx Error Log
/var/log/nginx/error.log

# PHP Error Log (varies by configuration)
/var/log/php-errors.log
/var/log/php.log
/home/username/public_html/error_log

# Mail Log
/var/log/maillog
/var/log/mail.log

Once you SSH into your server, you can read logs using standard Unix commands:

# View entire log file
cat /var/log/apache2/access.log

# View last 20 lines (most recent)
tail -20 /var/log/apache2/access.log

# View first 20 lines
head -20 /var/log/apache2/access.log

# View log page by page (press space to scroll)
less /var/log/apache2/access.log

Alternatively, download the log file via your hosting's file manager and view it on your local machine, which is often more convenient for analysis.

Apache/Nginx Access Logs & Combined Log Format

Access logs record every HTTP request to your website. They follow a standard format called "Combined Log Format":

203.0.113.5 - - [29/Jun/2026:10:23:14 +0700] "GET /index.php HTTP/1.1" 200 2326 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"

Each part of this log entry means:

From this information, you can see where visitors come from, what browser they use, which pages they access, and whether requests succeeded or failed. Many 404s might indicate broken links; many 500s indicate a server-side error in your application.

PHP Error Log: Finding Errors That Cause Website Crashes

When your PHP-based website encounters an error β€” syntax error, undefined function, undefined variable β€” that information goes into the PHP error log. This file is typically configured in php.ini and varies by hosting provider:

/var/log/php-errors.log
/var/log/php.log
/home/username/public_html/error_log

Example PHP error log entries:

[29-Jun-2026 10:25:31 Asia/Bangkok] PHP Fatal error: Call to undefined function mysql_connect() in /home/user/public_html/db.php on line 15

[29-Jun-2026 10:26:45 Asia/Bangkok] PHP Warning: Undefined variable: $username in /home/user/public_html/login.php on line 42

[29-Jun-2026 10:27:12 Asia/Bangkok] PHP Parse error: syntax error, unexpected '}' in /home/user/public_html/config.php on line 23

Each error entry shows the exact file, line number, and error type. This makes it easy for developers to fix problems instantly. Even warnings should be addressed, as they often lead to larger failures later.

Using Grep & Awk to Analyze Logs on Command Line

When log files grow to millions of lines, manual reading becomes impractical. Use shell commands to extract exactly what you need. The most useful commands are grep (filter), awk (parse), sort, and uniq:

# Count 404 errors
grep " 404 " /var/log/apache2/access.log | wc -l

# Count 500 errors
grep " 500 " /var/log/apache2/access.log | wc -l

# Top 20 IPs by request count
awk '{print $1}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -20

# Top URLs causing 404 errors
grep " 404 " /var/log/apache2/access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head -10

# Browser distribution of visitors
awk -F'"' '{print $6}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -10

# Count requests on a specific date
grep "29/Jun/2026" /var/log/apache2/access.log | wc -l

# Find all errors from a specific IP
grep "203.0.113.5" /var/log/apache2/access.log | grep " 404 "

The awk command is powerful for parsing structured log data. By specifying fields (columns), you can extract exactly what you need. For example, awk '{print $1}' prints only the first field (IP address) of each access log line.

AWStats & GoAccess: Free Log Analysis Tools

For analyzing very large logs, two free tools stand out: AWStats and GoAccess.

AWStats is an older but still popular log analysis tool. Most hosting with cPanel includes it. AWStats analyzes your access log and generates an HTML report showing:

GoAccess is a newer tool with real-time capabilities and better flexibility. If you have VPS control, you can install and use GoAccess:

# Install GoAccess
sudo apt-get install goaccess

# Analyze an access log
goaccess /var/log/apache2/access.log -a

# Generate HTML report
goaccess /var/log/apache2/access.log -a -o html > report.html

GoAccess displays a real-time dashboard showing hits, visitors, bandwidth, top pages, top IPs, browser distribution, and more. This visual representation makes it easy to understand your traffic at a glance.

Large Log Files: What To Do When They Grow Too Big

Log files grow quickly. A high-traffic website's access log can grow hundreds of MB per day, consuming valuable disk space. Three approaches help manage this:

1. Logrotate β€” Linux automatically rotates logs using logrotate, which archives old logs and keeps only recent ones. Example configuration:

/var/log/apache2/*.log {
  daily
  missingok
  rotate 14
  compress
  delaycompress
  notifempty
  create 0640 www-data adm
  sharedscripts
  postrotate
    if [ -f "var/run/apache2.pid" ]; then
      /etc/init.d/apache2 reload > /dev/null
    fi
  endscript
}

2. Truncate Logs β€” If disk space is critical, you can clear log contents to free up space immediately:

# Truncate Apache access log
> /var/log/apache2/access.log

# Truncate PHP error log
> /var/log/php-errors.log

3. Delete Old Logs β€” Remove logs older than a certain number of days:

# Delete logs older than 30 days
find /var/log -name "*.log" -mtime +30 -delete

Many hosting providers manage log rotation automatically, but if disk space becomes an issue, contact support β€” they can often extend log retention or set up custom rotation policies.

Detecting Hacking Attempts from Access Logs

Beyond troubleshooting, access logs reveal security threats. Watch for patterns like:

# Top IPs by request count (may reveal bot activity)
awk '{print $1}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -10

# IPs generating most 404 errors (vulnerability scanning)
grep " 404 " /var/log/apache2/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10

# Search for SQL injection patterns
grep -E "union|select|where|and|or|drop|insert|update|delete" /var/log/apache2/access.log

# Find path traversal attempts
grep "\.\.\/" /var/log/apache2/access.log

If you identify suspicious IPs, block them using firewall rules (.htaccess, iptables, or WAF) to prevent further attacks. Install a security plugin or WAF for additional protection.

Real-time Log Monitoring with Tail -f

To watch logs as events happen (live), use the tail -f command:

# Monitor access log in real-time
tail -f /var/log/apache2/access.log

# Monitor PHP error log in real-time
tail -f /var/log/php-errors.log

# Monitor web server error log in real-time
tail -f /var/log/apache2/error.log

This command streams new log entries as they're written, allowing real-time debugging. Press Ctrl+C to stop.

Combine tail -f with grep to monitor only events you care about:

# Monitor only 404 and 500 errors
tail -f /var/log/apache2/access.log | grep -E " (404|500) "

# Monitor requests from a specific IP
tail -f /var/log/apache2/access.log | grep "203.0.113.5"
RecommendedAsiaGB.com β€” Web hosting & VPS we use and recommend. Servers in Thailand and Singapore, SSD storage, DirectAdmin control panel, 24-hour Thai language support, 99% uptime.

AsiaGB.com β€” hosting & VPS we recommend. TH/SG servers, SSD storage, DirectAdmin, 24/7 Thai support, 99% uptime.

Visit AsiaGB β†’

Frequently Asked Questions

How long should logs be kept?
Most hosting keeps logs for 7-30 days depending on disk space and provider policy. For longer retention, request it from support or set up custom log archiving. For compliance reasons, some businesses require 90+ days of retention.
What are .gz files in logs?
These are gzip-compressed logs. To view them, decompress first using gunzip or zcat command. Compression saves disk space for archived logs.
How do I know if my site is being hacked?
Check access logs for 404 storms from single IPs, SQL injection patterns in URLs, or path traversal attempts. Check error logs for unauthorized access errors. Install a security plugin or Web Application Firewall (WAF) for protection. Monitor regularly and react quickly to suspicious activity.
PHP error log doesn't appear. What do I do?
Your hosting may have disabled error logging in php.ini. Ask support to enable it, or configure it yourself via .htaccess with directives like php_flag log_errors on and php_value error_log /path/to/error_log.
Can I download logs from my hosting?
Yes. Most hosting provides a file manager (cPanel or DirectAdmin) where you can download logs. You can also use SSH or FTP to download log files to your computer for analysis.