Ruachost

How to Check Apache Logs in Ubuntu: A Step-by-Step Guide

Learn how to check Apache logs on Ubuntu, explore formats, and use logs for server management in this comprehensive guide.

Ruachost Editorial31 October 2026 9 min read
How to Check Apache Logs in Ubuntu: A Step-by-Step Guide

Apache logs provide a detailed record of requests, errors, and server events. On Ubuntu, checking these records is often the fastest way to diagnose broken pages, permission problems, unexpected traffic, and application failures.

This guide explains where Ubuntu stores Apache logs, how to inspect them safely from the terminal, and how to interpret common entries. You will also learn how to monitor activity in real time, analyze HTTP status codes, find archived records, and prevent logs from consuming excessive disk space.

Introduction to Apache Logs#

Apache usually maintains two primary types of logs: access logs and error logs. Together, they show what visitors requested and how the server handled those requests.

Log type

Primary purpose

Typical information

Access log

Records HTTP requests

IP, time, URL, status, response size

Error log

Records server problems

Severity, module, client, error message

The access log answers questions such as:

  • Which URL did a visitor request?
  • Did Apache return a successful response?
  • Which IP address made the request?
  • Are bots repeatedly requesting missing files?
  • How many requests resulted in 404 or 500 responses?

The error log provides context when something goes wrong. It can reveal configuration mistakes, inaccessible files, application errors, failed modules, or directories that Apache cannot read.

Logs are therefore useful for more than emergency troubleshooting. Regular inspection can identify broken links, recurring application failures, suspicious scans, and performance patterns before they become serious problems.

Understanding Apache Log Files on Ubuntu#

On a standard Ubuntu installation, Apache writes requests to access.log and operational problems to error.log. The Apache HTTP Server documentation explains that logging behavior is controlled through configuration directives, including CustomLog, LogFormat, and ErrorLog.

The access log is normally updated whenever Apache processes a request. Depending on the configured format, each line can contain:

  • The requesting client’s IP address
  • An authenticated username, when applicable
  • The request date and time
  • The HTTP method, such as GET or POST
  • The requested path
  • The HTTP protocol version
  • The response status code
  • The response size
  • The referring page
  • The browser or client user agent

The error log is not limited to HTTP error responses. A visitor receiving a 404 does not necessarily produce a detailed error-log message, for example. Conversely, the error log can contain startup warnings and configuration failures even when no visitor has made a request.

Apache also supports different severity levels, including emerg, alert, crit, error, warn, notice, info, and debug. A production server commonly uses a moderate level such as warn; debug logging can generate substantial data and should normally be enabled only during focused investigation.

Common Apache Log Locations on Ubuntu#

Ubuntu and Debian systems normally store Apache logs under /var/log/apache2/, as described in Ubuntu’s guide to viewing and monitoring log files. The APACHE_LOG_DIR variable is generally defined in /etc/apache2/envvars.

Path

Contents

/var/log/apache2/access.log

Requests handled by Apache

/var/log/apache2/error.log

Errors, warnings, and server events

/var/log/apache2/other_vhosts_access.log

Requests for configured virtual hosts

/etc/apache2/envvars

Apache environment variables

/etc/apache2/sites-available/

Available virtual-host configurations

/etc/logrotate.d/apache2

Rotation and retention rules

These paths are defaults rather than guarantees. A virtual host can write to a separate file, which is helpful when one server hosts several websites.

To inspect Apache’s virtual-host mapping, run sudo apache2ctl -S. You can also search the Apache configuration for logging directives with sudo grep -R --include=*.conf -E "ErrorLog|CustomLog" /etc/apache2/. This reveals custom paths declared in virtual-host and configuration files.

If Apache reports AH02291: Cannot access directory during startup, a configured log directory may not exist or may have unsuitable permissions. After correcting the directory, run sudo apachectl configtest before reloading the service.

How to Access Apache Logs Using the Terminal#

Apache logs are commonly readable by root and members of Ubuntu’s adm group. If your account cannot open them, use sudo rather than changing the files to unsafe permissions.

Command

Best use

sudo less /var/log/apache2/error.log

Browse and search a complete log

sudo tail -n 20 /var/log/apache2/access.log

Display the latest 20 requests

sudo tail -f /var/log/apache2/error.log

Watch new errors in real time

sudo grep -i "error" /var/log/apache2/error.log

Find matching messages

sudo zgrep "search-term" /var/log/apache2/access.log*

Search current and compressed logs

Use less when you need to investigate a large file without loading it into an editor. Inside less, press /, enter a search term, and press Enter. Use n to move to the next match and q to exit.

The tail -f command is especially useful when reproducing a problem. Start the command, repeat the failing action in your browser, and watch for new messages. Press Ctrl+C when you have finished.

For focused monitoring, pipe live output through a filter. For example, sudo tail -f /var/log/apache2/access.log | grep --line-buffered " 500 " displays new requests returning status 500.

If you regularly administer the server, membership in the adm group may be more convenient than repeatedly using elevated privileges. The command sudo usermod -aG adm $USER adds the current user, but you must sign out and back in before the new group membership takes effect. Access should still be limited to trusted administrators because logs can contain IP addresses, requested URLs, and other sensitive operational information.

Interpreting Apache Log Entries#

Apache commonly uses either the Common Log Format or Combined Log Format. Combined format contains the Common fields plus the referrer and user agent.

Format

Core request data

Referrer

User agent

Common

Yes

No

No

Combined

Yes

Yes

Yes

A Combined-format entry might resemble:

127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /image.gif HTTP/1.0" 200 2326 "https://example.com/start" "Mozilla/5.0"

Read it from left to right:

Field

Example

Meaning

Client

127.0.0.1

Requesting IP address

User

frank

Authenticated user, if present

Time

[10/Oct/2000:13:55:36 -0700]

Request time and timezone

Request

GET /image.gif HTTP/1.0

Method, resource, and protocol

Status

200

HTTP response code

Bytes

2326

Response body size

Referrer

https://example.com/start

Referring page

User agent

Mozilla/5.0

Browser, bot, or HTTP client

Status codes provide a quick indication of the outcome. A 2xx response generally means success, 3xx indicates redirection, 4xx means the request could not be fulfilled as submitted, and 5xx indicates a server-side failure.

Do not rely on one field alone. A user agent can be forged, and repeated 404 responses may reflect ordinary broken links or automated scanning. Look at the requested paths, frequency, source addresses, timestamps, and related error-log entries together.

Error-log entries use a different structure and may include a timestamp, module, severity, process ID, client address, and message. The message is usually the most actionable part, but the module name can identify whether the problem originated in Apache core, SSL handling, a proxy, PHP integration, or another component.

Using Logs for Troubleshooting and Performance Analysis#

Begin with a precise time window. Reproduce the issue if possible, note the time, and then compare access.log with error.log. This prevents unrelated warnings from distracting you.

Common investigations include:

  • Missing pages: Run sudo grep " 404 " /var/log/apache2/access.log | tail -n 50. Check whether the requested path is incorrect, the file is absent, or routing rules are failing.
  • Server errors: Use sudo grep " 500 " /var/log/apache2/access.log | tail -n 50, then inspect error-log entries from the same timestamps.
  • Permission failures: Search the error log with sudo grep -i "permission denied" /var/log/apache2/error.log. Verify directory traversal permissions as well as the target file.
  • Specific visitor activity: Use sudo grep "CLIENT_IP" /var/log/apache2/access.log | less, replacing CLIENT_IP with the address under investigation.
  • Problematic URL: Search both logs for the path to determine how often it was requested and whether Apache recorded a related failure.

You can summarize status codes with sudo awk '{print $9}' /var/log/apache2/access.log | sort | uniq -c | sort -rn. In standard Common or Combined format, the ninth field is the status code. Custom formats may place it elsewhere, so confirm the active LogFormat before relying on this command.

A large number of 500 responses deserves immediate attention, while a sudden rise in 404s may indicate a broken deployment, outdated links, or automated probing. Repeated requests to login pages, environment files, or known administrative paths can also warrant security review.

Logs can provide useful performance clues, but default formats do not necessarily record request duration. Apache can be configured to include timing fields such as %D, which reports processing time in microseconds. Before changing the format, consider compatibility with any existing analysis tools and test the configuration with sudo apachectl configtest.

Tips for Managing Log Files Efficiently#

Apache logs grow continuously on an active server. Ubuntu normally uses logrotate, with Apache’s rules stored in /etc/logrotate.d/apache2. Rotation creates files such as access.log.1 and compressed archives such as access.log.2.gz.

A typical Ubuntu configuration rotates logs daily, retains a set of older files, and compresses older records. However, administrators should inspect the server’s actual configuration rather than assuming its retention settings.

Follow these practices:

  • Monitor available disk space with tools such as df -h and check log-directory usage with sudo du -sh /var/log/apache2/.
  • Search compressed archives with zgrep instead of manually extracting them.
  • Adjust retention according to traffic, disk capacity, security requirements, and applicable privacy obligations.
  • Avoid deleting the active log while Apache is writing to it. Use the configured rotation process.
  • Restrict log access because URLs, query strings, IP addresses, and error details may contain sensitive information.
  • Keep system time and timezone configuration accurate so events can be correlated across Apache, applications, databases, and firewalls.
  • Review high-volume errors instead of merely retaining them. Repeated warnings can consume storage while hiding more important events.

After editing Apache or log-rotation settings, validate the configuration and monitor the next rotation. Good log management preserves enough history for investigation without allowing old records to exhaust server storage.

Conclusion: Best Practices for Apache Log Monitoring#

Effective Apache monitoring starts with knowing both the default files and any virtual-host-specific paths. Use tail -f while reproducing live problems, less for careful review, grep for targeted searches, and zgrep for archived logs. Correlate access and error entries by timestamp rather than treating either file as a complete account on its own.

Protect log permissions, verify rotation regularly, watch disk usage, and investigate unusual changes in status-code patterns. These habits turn Apache logs from passive records into practical tools for reliability, security, and performance management.

If you would prefer managed hosting tools and convenient server administration, explore Ruachost to find a suitable next step for your website.

Found this useful? Share it.

Keep reading

More from the journal.