linux view apache logs

In Linux, apache logs (error logs and access logs) provide useful information for system administrators to solve and locate problems.

For example, troubleshoot the Web server to protect the system from malicious intrusions, or perform various analyses to monitor the HTTP server.

Depending on the configuration of your Web server, its error/access logs may be placed in different locations on your system.

This article can help you find and view the Apache error log on Linux.

Apache error log location on Debian, Ubuntu or Linux Mint

Default error log

On Debian-based Linux, the default location of the system-wide Apache error log is /var/log/apache2/error.log. The default location can be modified by editing the Apache configuration file.

Custom error log

To find the custom error log location, open /etc/apache2/apache2.conf with a text editor, and then look for the line that starts with ErrorLog, which specifies the location of the custom Apache error log file.

For example, the following line can be found in the unmodified Apache configuration file:

ErrorLog ${APACHE_LOG_DIR}/error.log

In this example, the location is configured using the APACHELOGDIR environment variable, which is already defined in /etc/apache2/envvars.

export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

In a production environment, ErrorLog may point to any path in your Linux system.

Use a custom error log for the virtual host

If a virtual host is used in the Apache Web server, the ErrorLog directive may be specified in the virtual host container. In this case, the system-wide error log location mentioned above will be ignored.

After the virtual host is enabled, each virtual host can define its own custom error log location. To find the location of the error log for a particular virtual host, you can open /etc/apache2/sites-enabled/.conf, and then look for the ErrorLog command, which will display the error log file specified by the site.

Apache error log location on CentOS, Fedora or RHEL

Default error log

In Red Hat-based Linux, the system-wide Apache error log file is placed in /var/log/httpd/error_log by default. This default location can be customized by modifying the Apache configuration file.

Custom error log

To find the custom location of the Apache error log, open /etc/httpd/conf/httpd.conf with a text editor, and then look for ServerRoot. This parameter shows the top level of the Apache Web server directory tree. The log files and configuration are located at In the directory tree. E.g:

ServerRoot "/etc/httpd"

Now, look for the line that starts with ErrorLog, which indicates where the Apache Web server writes the error log. Note that the location specified is the relative location of the ServerRoot value. E.g:

ErrorLog "log/error_log"

Combining the above two instructions, you can get the complete error log path, which is /etc/httpd/logs/errorlog by default. In a freshly installed Apache, this is a symbolic link to /var/log/httpd/errorlog.

Similarly, in a production environment, ErrorLog may point to any location in your Linux system.

Use a custom error log for the virtual host

If you enable virtual hosts, you can find the error log location of each virtual host by checking /etc/httpd/conf/httpd.conf (or any other file that defines virtual hosts). Look for ErrorLog in the separate virtual host section. For example, in the virtual hosting section below, the location of the error log is /var/www/xmodulo.com/logs/error_log.

<VirtualHost *:80>
  ServerAdmin [email protected]
  DocumentRoot /var/www/xmodulo.com/public_html
  ServerName www.xmodulo.com
  ServerAlias xmodulo.com
  ErrorLog /var/www/xmodulo.com/logs/error_log
  CustomLog /var/www/xmodulo.com/logs/access_log
<VirtualHost>

Log viewing

In the previous article, we introduced various log viewing methods for different scenarios. For apache log view, we still use tail -f command or grep command.

Add a Comment

Your email address will not be published.