How to View and Analyze Apache Logs on Hosting Accounts

Article By:
How to View and Analyze Apache Logs on Hosting Accounts

Many hosting providers use Apache web servers to host their WordPress, Joomla and many other applications. Apache web servers keep records of user activities and errors in log files, used by web administrators to analyze user records and diagnose errors on Apache web servers. This blog discusses Apache log files, their accessibility on various hosting accounts and how to interpret them

Apache or Apache HTTP server is a top-rated open source web server software, commonly used by hosting providers as their web servers to host WordPress, Joomla, Drupal and many other CMS. Whether you are a hosting provider, a site administrator, or an owner of a site, web server errors are bound to happen. 

Logs are records of transactions or events of a particular application commonly stored as plain text files known as log files. If you face any web server issues, a log file is probably the first place to understand further what has gone wrong and tracing its route cause. This blog will give you an overview of Apache log files, how to access and interpret them, and either solve the error on your own or hand it to your support team for further assistance.

Apache Access Log

An Apache Access log stores information on the events that occurred in your  web server. A web server administrator can gain the following information from the Apache Access log and use them to understand the behaviour of user requests for the site:

  • Incoming requests to your web server
  • Users viewing and accessing your site
  • Status of requests
  • Request response times 

 

Apache Error Log

Error logs are considered the most important log file. An Apache Error Log records any errors in the webserver during the processing of requests, such as missing files or invalid requests. It also records the runtime errors of the Apache web servers. Information in the error log helps support teams or developers diagnose errors quickly.

Apache Log File Location

Apache server log files are stored in a separate folder, and their location depends on the operating system or hosting account type you are currently using.

View and Download Apache Logs for Hosting Accounts

Let’s look at the ways to access the Apache logs for different hosting types. Examples here refer to A2 hosting services; however, this guide applies to hosting providers with similar setups.

 For more information on accessing Apache logs for different hosting accounts, refer to this article.

Access Apache Logs in Shared or Reseller Hosting 

To access the Apache logs from a shared hosting account, use the cPanel dashboard to retrieve the access or error logs. To access the Apache access log, first, you need to download the Raw access log. A raw access log contains information on your site’s visitors in a plain format used to analyze its traffic.

Apache Access Logs

Read more about how to configure and download the Apache access log for shared hosting in this article

Next, access the Metrics section on cPanel and click on Errors to show the last 300 entries in your error log.

Access Apache Logs in Managed Dedicated and VPS Hosting

If you are a Managed, Dedicated, or VPS Hosting user, you can use your cPanel to access the apache log files in the following directory: /usr/local/apache/logs/access_log. You can also use the Metrics section on cPanel for a one click access to your error log:

Logs on cPanel

Access Apache logs on a Dedicated (Unmanaged)  and VPS Hosting

With Dedicated or VPS hosting, you have root access, and this allows you to access and manage the Apache logs files. All Log files are stored in the var/log/ directory. 

  • Use  SSH and type the following command to view the last 100 lines of the Access log file:
    sudo tail -100 /etc/httpd/logs/access_log
  • Use  SSH and type the following command to view the last 100 lines of the Access log file:

sudo tail -100 /etc/httpd/logs/error_log

How to Read the Apache Access Log

Now that you’ve learned how to access the error logs; this section will give an overview of how to interpret some parts of the access log. Download the access log file and open it using a text editor. You may also choose to format the log file output for readability. In this example, the log file is using the Combined Log Format, where it gives additional information for debugging purposes. Here are the fields on a single line in the access log file:

10.xx.xx.xx – – [30/Jul/2021:00:38:46 -0400] “GET /Joomla2/administrator/index.php?option=com_ajax&format=json HTTP/1.1” 200 60 “http://sarojini-test.com/Joomla2/administrator/index.php?option=com_menus&view=item&client_id=0&menutype=mainmenu&layout=edit” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36”

 

The Files Decoded:

  • 10.xx.xx.xxIP address of the client that made the request
  • 30/Jul/2021:00:38:46 -0400] – Date and time of request
  • GET /Joomla2/administrator/index.php?option=com_ajax&format=json HTTP/1.1″  – request type and resource being requested
  • 200 – request type and resource being requested
  • 60 – size of the object returned to the client
  • http://saaaai-test.com/Joomla2/administrator/index.php?option=com_menus&view=item&client_id=0&menutype=mainmenu&layout=edit: HTTP represents the address from which the request for the resource originated.
  • “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36” – The browser by client to access the resource access client request.

Conclusion

In summary, Apache log files are essential for a web administrator to understand events on their website and gain insights on visitor requests or runtime errors on Apache servers. More often than not, the error logs are commonly used and deemed vital as they can be used to understand the root cause of an error and help the support team resolve them quickly to avoid site downtime. There are many resources available on error logging, and if you are using cPanel, refer to this link to understand further on logging features using cPanel.

Dedicated

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. For more information about cookies, see our Privacy Policy.