How To Troubleshoot Common Apache Errors – DigitalOcean

Getting Started

There are three main commands and a set of common log locations that you can use to start troubleshooting Apache errors. Typically, when troubleshooting Apache, you’ll use these commands in the order listed here, and then examine the log files for specific diagnostic data.

The commands you will commonly use to troubleshoot Apache on most Linux distributions are:

systemctl – Used to

  • control and interact with Linux services through the systemd service manager
  • .

  • journalctl – Used to query and view logs generated by systemd
  • .

  • apachectl – When troubleshooting, this command is used to check Apache settings.

These commands, how to use them, and Apache log locations where you can find additional error information are described in more detail in the following sections

.

systemctl Commands for

Apache

To troubleshoot common Apache errors using the systemd service manager, the first step is to inspect the status of Apache processes on your system. The following systemctl commands will query systemd for the status of Apache processes.

On Ubuntu and Debian systems they run:

  1. sudo systemctl status apache2.service

-l -no-pager

The -l flag will ensure that the output is not truncated or elipsed. The -no-pager indicator will make sure that the output goes directly to your terminal without requiring any interaction on your part to view it. You should receive output like this

: Output● apache2.service – Apache HTTP server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; provider preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Mon 2020-07-13 14:43:35 UTC; 1 day 4h ago Process: 929 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 1346 (apache2) Tasks: 55 (limit: 4702) CGroup: /system.slice/apache2.service ├─1346 /usr/sbin/apache2 -k start . . .

To inspect the Apache process on CentOS and Fedora systems, run

:

  1. sudo systemctl status
  2. httpd.service -l -no-pager

You should receive output like this

: Output● httpd.service – Apache HTTP server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; provider preset: disabled) Active: active (running) since Tue 2020-07-14 19:46:52 UTC; 3s Aug Documents: man:httpd.service(8) Main PID: 21217 (httpd) Status: “Started, listening on: port 80” Tasks: 213 (limit: 2881) Memory: 16.6M CGroup: /system.slice/httpd.service ├─21217 /usr/sbin/httpd -DFOREGROUND . . . Jul 14 19:46:52 localhost.localdomain httpd[21217]: Server configured, listening on: port 80

In any case, take note of the active line in the output. If your Apache server does not show active (running) as highlighted in the examples above, but you expect it to, there may be an error. Usually, if there is a problem, you will have a line like the following in your output (note the failed part highlighted):

Example of OutputActive error: failed (Result: exit code) from Tue 2020-07-14 20:01:29 UTC; 1s Aug

If there is a problem with your Apache process or configuration, you can fix it further by using

the journalctl command.

journalctl Commands for Apache

To inspect systemd logs for Apache, you can use the journalctl command. The systemd logs for Apache will usually indicate if there is a problem with starting or managing the Apache process.

These logs are separate from Apache request and error logs. journalctl displays systemd logs that describe the Apache service itself, from startup to shutdown, along with any process errors that may be encountered along the way.

On Ubuntu and Debian systems use the following command to examine the logs

:

  1. sudo journalctl -u apache2.service -since today -no-pager The -since today

flag will limit the output of the command to log entries that start only at 00:00:00 on the current day. Using this option will help restrict the volume of registry entries that you should examine when checking for errors. You should receive output like the following

: OutputJul 14 20:12:14 ubuntu2004 systemd[1]: Starting Apache HTTP Server… Jul 14 20:12:14 ubuntu2004 systemd[1]: Apache HTTP server started.

If you are using a CentOS or Fedora-based system, use this version of the command

:

  1. sudo journalctl -u httpd.service -since today -no-pager

You should receive output like the following

: OutputJul 14 20:13:09 centos8 systemd[1]: Starting Apache HTTP Server… . . . Jul 14 20:13:10 centos8 httpd[21591]: Server configured, listening on: port 80

If there is an error, you will have a line in the output that is similar to the following, with the main difference between Linux distributions being the highlighted part

of yourhostname: Error output exampleJul 14 20:13:37 yourhostname systemd[1]: Error starting Apache HTTP server.

If your Apache server has errors in the journalctl logs like the example above, then the next step to troubleshoot potential issues is to investigate the Apache configuration using the apachectl command-line tool.

Troubleshooting apachectl Most Linux distributions include the apachectl utility with Apache. apachectl

is an invaluable tool to help detect and diagnose

Apache configuration issues. To troubleshoot problems with apachectl, test your Apache configuration using the

apachectl

configtest command. The tool will scan your Apache files and detect any errors or missing settings before attempting to start the server.

Run the command like this on Ubuntu, Debian, CentOS and Fedora-based distributions

:

  1. sudo apachectl configtest

A working Apache configuration will result in output like the following:

OutputSyntax OK

Depending on your Linux distribution, there may be other lines mixed with the output, but the important line is the one that says Syntax OK.

If there is an error in your Apache configuration, such as a directive referencing a module that is not enabled or even a single typo, apachectl will detect it and attempt to notify you about the problem.

For example, attempting to use directives for an Apache module that is not enabled will result in apachectl configuration test messages such as the following:

Example of error OutputAH00526: Syntax error on line 232 of /etc/apache2/apache2.conf: Invalid command ‘SSLEngine’, perhaps misspelled or defined by a module not included in the server configuration Action ‘configtest’ failed. The Apache error log may have more information.

In this example, the ssl module is not enabled, so the SSLEngine directive fails when the configuration is tested. The last line also indicates that the Apache error log may have more information, which is the next place to look for more detailed debugging information.

Apache log

files Apache log files are a very useful troubleshooting resource. Generally, any error you receive in a browser or other HTTP client will have a corresponding entry in the Apache logs. Sometimes Apache will also generate errors related to configuration, built-in modules, and other debugging information in your log files.

To examine the log files for errors when troubleshooting Apache on a Fedora, CentOS, or RedHat server, examine the /var/log/httpd/error_log file.

If you are troubleshooting a Debian or Ubuntu derived system, examine /var/log/apache2/error.log for errors using a tool such as tail or less. For example, to view the last two

lines of the error log using tail, run the following command:

  1. sudo tail -n 2 /var/log/apache2/error.log

Replace the number of

lines you want to examine instead of the number 2 in the command. On a CentOS or Fedora system, the log file to examine is /var/log/httpd/error_log.

An example error will resemble the following lines, regardless of the Linux distribution you are using to run your Apache server:

Error log examples[Wed Jul 15 01:34:12.093005 2020] [proxy:error] [pid 13949:tid 140150453516032] (13)Permission denied: AH00957: HTTP: Attempt to connect to 127.0.0.1:9090 (127.0.0.1) error [Wed Jul 15 01:34:12.093078 2020] [proxy_http:error] [pid 13949:tid 140150453516032] [client 127.0.0.1:42480] AH01114: HTTP: Error connecting to backend: 127.0.0.1

The two lines in this output are different error messages. Both refer to the module causing the error (proxy on the first line, proxy_http on the second) and include an error code that is specific to the module. The first, AH00957, indicates that the Apache server tried to connect to a backend server (127.0.0.1 on port 9090 in this case) using the proxy module but did not.

The second error stems from the first: AH01114 is a proxy_http module error that also indicates that Apache could not connect to the backend server configured to make an HTTP request.

These example lines are for illustrative purposes only. If you are diagnosing errors with your Apache server, it is likely that the error lines in your logs have different contents than these. Regardless of your Linux distribution, the format of any error line in your logs will include the relevant Apache module and error code, as well as a text description of the error.

Once you have an idea of what might be causing problems with your Apache server, you can continue to investigate and fix the problem. Error code and text description are especially useful, as they give you explicit, specific terms that you can use to narrow down the range of possible causes of a problem.

Conclusion

Apache error troubleshooting can range from diagnosing errors with the service itself, to locating misconfigured options for modules, to examining custom access control rules in detail. This introduction to diagnosing problems with Apache explains how to use a number of utilities to help narrow down the potential causes of errors. You’ll usually use these utilities in the same order, though you can always skip some, or start straight with examining the logs if you have a general idea of what the problem might be.

However, as a general sequence for problem solving, it is helpful to be methodical and use these tools in the order described. Start troubleshooting with systemctl to examine the status of the Apache server. If you need more information, examine the systemd logs for Apache using the journalctl command. If the problem is still not apparent after checking journalctl, testing the Apache configuration using apachectl configtest is the next step. Finally, for in-depth troubleshooting, examining Apache log files will usually indicate a specific error, with helpful diagnostic messages and error codes.

The rest of the tutorials in this series will examine some common errors you may encounter when using Apache in more detail.

Contact US