English translation
13. Check Apache2 Service Status and Error Logs
In the previous tutorial, we successfully accessed our test website through a web browser. This tutorial focuses on how to check the status of Apache2 and examine its error logs—ensuring your server runs smoothly and enabling you to detect potential issues promptly.
Checking the Apache2 Service Status
To view the current status of Apache2, run the following command:
sudo systemctl status apache2
This command displays the current operational state of the Apache2 service. If the service is running normally, you should see output similar to the following:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-10-01 12:34:56 UTC; 5min ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 1234 (apache2)
Tasks: 6 (limit: 1163)
Memory: 15.2M
CGroup: /system.slice/apache2.service
├─1234 /usr/sbin/apache2 -k start
├─1235 /usr/sbin/apache2 -k start
└─1236 /usr/sbin/apache2 -k start
In this output, Active: active (running) confirms that Apache2 is currently running.
Viewing Apache2 Error Logs
Errors are common during website operation, and Apache2 records them in designated log files. By default, the error log resides at /var/log/apache2/error.log. To view its contents, use:
sudo tail -f /var/log/apache2/error.log
The tail -f command streams the most recent entries from the error log in real time. Here’s an example of possible output:
[Sat Oct 01 12:35:12.345678 2023] [core:error] [pid 1234] [client 192.168.1.1:54321] Directory index forbidden by Options directive: /var/www/html/
[Sat Oct 01 12:36:15.123456 2023] [php:error] [pid 1235] [client 192.168.1.1:54321] PHP Parse error: syntax error, unexpected '}' in /var/www/html/index.php on line 12
In the above output:
- The first line indicates that directory listing was denied due to restrictive configuration directives.
- The second line reports a PHP syntax error—in this case, an unexpected
}character on line 12 of/var/www/html/index.php.
Case Study: Analyzing Error Logs
Suppose you encounter a “403 Forbidden” error while accessing your website. You can consult the error log to identify the root cause.
First, start monitoring the error log:
sudo tail -f /var/log/apache2/error.log
Then, refresh the page in your browser. You may see an entry like:
[Sat Oct 01 12:40:00.000000 2023] [authz_core:error] [pid 1236] [client 192.168.1.1:54321] AH01630: client denied by server configuration: /var/www/html/
This message indicates that access to /var/www/html/ was denied due to server configuration. To resolve it, inspect your apache2.conf file or the relevant virtual host configuration and verify that the <Directory> directive is correctly configured—for example:
<Directory /var/www/html>
AllowOverride None
Require all granted
</Directory>
Conclusion
This tutorial has guided you through checking the Apache2 service status and reviewing its error logs. Mastering these tasks is essential for maintaining a healthy and reliable web server. As a best practice, regularly monitor both the service status and logs to ensure stability and proactively address issues.
In the next tutorial, we’ll cover Apache2 service management—including how to start, stop, and restart the service—to give you full control over your web server. Stay tuned!
Continue