Apache error codes are three-digit numbers returned by the Apache web server when something goes wrong during the processing of HTTP requests.
Some common Apache error codes include:
200 – OK
A 200 response code means the connection has been successful and the browser will serve the websites content.
You can see these in the access log files.
126.96.36.199 - - [16/Mar/2023:15:21:48 +0000] "GET / HTTP/1.0" 200 109196 "http://mydomain.io/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
206 – Partial Content
This code explains that the connection is only requesting parts of the website such as just the code with a wget command, this code can be fairly common.
301 – Moved Permanently
This code lets the browser know that the url has been moved permanently to a new location and to forward all future request to the new location.
302 – Moved Temporarily
This code is very similar to 301 but instead of a permanent move, it is temporary.
303 – See Other
This code is a way to redirect web applications to a new URL.
304 – Not Modified
This indicates that the browser has a cached copy of the website and the website has not had any modications since the browsers last visit.
400 – Bad Request
The server is not able to process the clients request due to something wrong with the client (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
401 – Unauthorized
Similar to 403 Forbidden, but specifically for when authentication is required to continue to the website.
403 – Forbidden
The request was valid, however the server is refusing the connection due to configuration settings.
404 – Not Found
The file requested resource could not be found but may be available again in the future. You might also run into a few other error codes that convey the same thing. Common variants include “Page Not Found” or “File Not Found.” Depending on which website you’re browsing, you might also see messages like “Product not Found.”
So, let’s take a look at some things you can do to try to fix a 404 error. In most cases, it’s likely that the page you’re looking for was moved or deleted. But, you can try this on the client end.
Refresh the Page
Double Check the Address
Perform a Search
Clear Your Browser Cache
Change your DNS Server
Check if the Website Has Temporary Issues
405 – Method Not Allowed
A request was made to the website which was different than it was programmed to handle such as using GET on a form which requires data to be presented via POST, or using PUT on a read-only resource.
406 – Not Acceptable
This code means that the server has blocked the request via mod_security.
413 – Request Entity Too Large
The request is larger than the server is willing or able to process.
500 – Internal Server Error
This error is generally specific to something written in the .htaccess file that is not valid syntax or the website file permissions are in correct.
501 – Not Implemented
The server was not programmed to handle the type of request, or it was not able to fulfill the request.
Now that we have the codes, let’s take a look at how to check for errors.
The commands that you will commonly use to troubleshoot Apache across most Linux distributions are:
systemctl – Used to control and interact with Linux services via the systemd service manager.
journalctl – Used to query and view the logs that are generated by systemd.
apachectl – When troubleshooting, this command is used to check Apache’s configuration.
Generally when you are troubleshooting Apache, you will use these commands in the order indicated here, and then examine log files for specific diagnostic data.
systemctl Commands for Apache
On Ubuntu and Debian.
sudo systemctl status apache2.service -l --no-pager
-l flag will ensure that output is not truncated or ellipsized. The
--no-pager flag will make sure that output will go directly to your terminal without requiring any interaction on your part to view it.
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2023-03-14 15:14:14 CDT; 1 day 18h ago Docs: https://httpd.apache.org/docs/2.4/ Process: 577 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Process: 7904 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS) Main PID: 606 (apache2) Tasks: 6 (limit: 2337) Memory: 36.8M CPU: 9.846s CGroup: /system.slice/apache2.service ├─ 606 /usr/sbin/apache2 -k start ├─7909 /usr/sbin/apache2 -k start ├─7910 /usr/sbin/apache2 -k start ├─7911 /usr/sbin/apache2 -k start ├─7912 /usr/sbin/apache2 -k start └─7913 /usr/sbin/apache2 -k start Mar 14 15:14:12 my.hostname.io systemd: Starting The Apache HTTP Server...
To inspect the Apache process on CentOS and Rocky systems run:
sudo systemctl status httpd.service -l --no-pager
Make a note of the “Active line” in the output. If your Apache server does not show active (running) there may be an error. If there is a problem, you will have a line like the following in your output (note the highlighted failed portion):
Active: failed (Result: exit-code) since Tue 2020-07-14 20:01:29 UTC; 1s ago
If there is an error it may look like the following:
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Thu 2023-03-16 10:15:04 CDT; 1min 7s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 9835 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE) CPU: 23ms Mar 16 10:15:04 my.hostname.io systemd: Starting The Apache HTTP Server... Mar 16 10:15:04 my.hostname.io apachectl: AH00526: Syntax error on line 93 of /etc/apache2/apache2.conf: Mar 16 10:15:04 my.hostname.io apachectl: Invalid command 'Time', perhaps misspelled or defined by a module not included in the server configuration Mar 16 10:15:04 my.hostname.io apachectl: Action 'start' failed. Mar 16 10:15:04 my.hostname.io apachectl: The Apache error log may have more information. Mar 16 10:15:04 my.hostname.io systemd: apache2.service: Control process exited, code=exited, status=1/FAILURE Mar 16 10:15:04 my.hostname.io systemd: apache2.service: Failed with result 'exit-code'. Mar 16 10:15:04 my.hostname.io systemd: Failed to start The Apache HTTP Server.
From here we can see the error and correct it:
Mar 16 10:15:04 my.hostname.io apachectl: AH00526: Syntax error on line 93 of /etc/apache2/apache2.conf:
journalctl Commands for Apache
To inspect the
systemd logs for Apache, you can use the
journalctl command. The
systemd logs for Apache will usually indicate whether there is a problem with starting or managing the Apache process.
These logs are separate from Apache’s request and error logs.
journalctl displays logs from
systemd 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
sudo journalctl -u apache2.service --since today --no-pager
--since today flag will limit the output of the command to log entries beginning at 00:00:00 of the current day only. Using this option will help restrict the volume of log entries that you need to examine when checking for errors. You should receive output like the following:
Output for a successful start
Journal file /email@example.com~ is truncated, ignoring file. -- Journal begins at Fri 2022-09-23 21:48:54 CDT, ends at Thu 2023-03-16 09:56:58 CDT. -- Mar 16 00:00:41 my.hostname.io systemd: Reloading The Apache HTTP Server. Mar 16 00:00:41 my.hostname.io systemd: Reloaded The Apache HTTP Server.
If you are using a CentOS or Fedora based system, use this version of the command:
sudo journalctl -u httpd.service --since today --no-pager
Jul 14 20:13:09 centos8 systemd: Starting The Apache HTTP Server... . . . Jul 14 20:13:10 centos8 httpd: 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:
Mar 16 10:15:04 centos8 systemd: Failed to start The Apache HTTP Server.
If your Apache server has errors in the journalctl logs the next step to troubleshoot using the apachectl command line tool.
Run the command like this on Ubuntu, Debian, CentOS, and Fedora based distributions:
sudo apachectl configtest
Output for success
If there is an error in your Apache configuration, apachectl will detect it and attempt to notify you.
Here is an error for example:
AH00526: Syntax error on line 93 of /etc/apache2/apache2.conf: Invalid command 'Time', 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 there is a Syntax error on line 93 of /etc/apache2/apache2.conf.
Apache Log Files
The log files are a goldmine for information.
For errors on a Fedora, CentOS, or RedHat server, examine the /var/log/httpd/error_log file.
For Debian or Ubuntu derived system, examine /var/log/apache2/error.log for errors.
Use “tail” to view logs:
Tail the log in real time allow you to load the page to see the errors live.
Debian or Ubuntu
sudo tail -f /var/log/apache2/error.log
View the last 5 lines:
sudo tail -n 5 /var/log/apache2/error.log
On CentOS or Rocky
sudo tail -f /var/log/httpd/error_log
View the last 5 lines:
sudo tail -n 5 /var/log/httpd/error_log
Read the information to see if there is a specific error.