Where are Apache File Access Logs Stored in Ubuntu?

Apache is a popular web server software that serves different web pages and other content on the Internet. It is free and open-source software on various operating systems, including Ubuntu. Apache stores various information related to the web server in log files, such as access.log, error.log, etc. These log files are essential for website administrators to monitor traffic, diagnose issues, and analyze website usage.

This article will illustrate different ways to find Apache file access logs stored in Ubuntu.

Where are Apache File Access Logs Stored in Ubuntu?

Apache file access logs are stored in a file called “access.log“. The location of this file depends on the configuration of the Apache server. By default, the access log files are usually stored in the “/var/log/apache2” directory on Ubuntu systems.

Method 1: Accessing Apache Logs Using Terminal

Before accessing the log file, it is necessary that Apache is already installed in the operating system. To install Apache, follow our article “How to Install Apache in Ubuntu”. 

Example 1: Using the cd Command to Navigate and View Apache Access Logs 

To present the Apache access logs file in the terminal, navigate to the Apache log directory by running the “cd” command. After that, list down the log files using the “ls” command:

$ cd /var/log/apache2/

The output shows that all Apache logs files are stored in the “apache2” directory.

View the Contents of the Access Logs 

To view the contents of the log files, use a text editor like nano or less. For example, to view the access.log file, run the following command:

$ sudo nano access.log

It opens the “access.log” file that contains all access log history. It includes the client’s IP address, request timestamp, the requested resource, HTTP status code, and response size.

Example 2: Using less Command to View the Contents of the Log Files 

Users can utilize the “less” command to visualize the contents of the log files in the terminal. For instance, to view the access.log file using the “less” command, run the following command:

$ sudo less access.log

It opens the access.log file and presents the client’s IP address, request timestamp, the requested resource, HTTP status code, and response size in a listed format. After that, users can press “Q” to exit the viewer.

Example 3: Using the tail Command to View the Last 4 Entries of the Access Log

To display the last four entries in the Apache configuration file, utilize the “tail” command with the “4” option by specifying the location of the access log file:

$ sudo tail -4 /var/log/apache2/access.log

It displays the last four Apache access log entries that are stored in the Apache configuration file.

Example 4: Using grep Command to View a Specific Term From Access Logs

Users can utilize the “grep” command by specifying the “GET” term to obtain logs that are related to this term in “/var/log/apache2/access.log“:

$ sudo grep GET /var/log/apache2/access.log

It accesses the Apache logs having the “GET” term in the access.log file including client’s IP address, request timestamp, the requested resource, HTTP status code, and response size.

Example 5: Display Apache Error Logs

To display the Apache error logs of the last two entries, use the “tail” command by specifying the  “/var/log/apache2/error.log” file:

$ sudo tail -2 /var/log/apache2/error.log

It shows a list of error logs from the Apache.

Method 2: Accessing Apache Logs Using Log Viewer

Ubuntu has a built-in log viewer called “gnome-system-log”. Here, the following steps make use of it to view the Apache logs:

Step 1: Install the gnome-system-log tool

To Install the gnome-system-log tool, utilize the “APT” package manager by running the following command:

$ sudo apt install gnome-system-log

The output shows that gnome-system-log has been successfully installed in the system.

Step 2: Launch the gnome-system-log Tool

To launch the gnome-system-log tool, specify the tool’s name in the following command:

$ sudo gnome-system-log

The highlighted section represents a list of all the Apache access logs in the log viewer.

Conclusion

In the Ubuntu-Linux based system, the Apache access log files are stored in the “/var/log/apache2” directory. These files contain details of all the requests made to the web server, including the client’s IP address, request timestamp, the requested resource, HTTP status code, and response size.

This article has explained two methods to access Apache logs and several examples on Ubuntu.

Over 500 Million Views on Our Blogs and YouTube! We’re inviting 10 businesses to partner with us and grow together. Click here to join us! ×