How to Troubleshoot and Fix Common Problems with Apache
Apache is a free, open-source and highly customisable software for hosting websites now a day. It is simple and easy to install, but it can run Apache into a problem. It has different configurations and settings in many places, so sometimes, it can be challenging to troubleshoot Apache errors for normal users.
Apache has three major commands and common log file locations that will help you to troubleshoot Apache errors. These commands are common in most Linux distributions.
systemctl - It is used to control and manage Linux services.
journalctl - It is used to display logs generated by systemd services.
apachectl - It is used to check the Apache configuration files for any error.
This post will show you how to troubleshoot and fix Apache errors.
Table Of Contents
- Steps to Troubleshoot and Fix Apache Errors
- Check Whether the Apache Service is Running
- Check Apache Server Configuration
- Check Apache Logs
- Check Other Services
Steps to Troubleshoot and Fix Apache Errors
Check Whether the Apache Service is Running
The first step to troubleshooting the Apache server is to ensure the Apache service is running and functioning.
For Debian and Ubuntu-based distributions, check the Apache service using the following command:
systemctl status apache2
For CentOS, Fedora and RHEL-based distributions, check the Apache service using the following command:
systemctl status httpd
If the Apache service is not running, then you will need to start it using the following command:
systemctl start apache2
systemctl start httpd
If your system was not able to start the Apache service, then you should get the following output:
apache2: unrecognized service Failed to restart apache2.service: Unit apache.service failed to load
To resolve the above error, you will need to check the Apache configuration file for any errors.
Check Apache Server Configuration
Apache provides some handy tools to check the Apache server for configuration errors.
For Debian and Ubuntu-based distributions, check Apache for any configuration error with the following command:
For CentOS, Fedora and RHEL-based distributions, check Apache for any configuration error with the following command:
If everything is fine, you should get the following output:
If there is an error in your Apache configuration, you should get the following output error:
AH00526: Syntax error on line 232 of /etc/apache2/apache2.conf: Action 'configtest' failed. The Apache error log may have more information.
Now, you can proceed to the next step to get more information about the error.
Check Apache Logs
Apache provides a journalctl command to inspect the systemd logs for Apache. The journalctl command will display logs from startup to shutdown and any process errors encountered along the way.
For Debian and Ubuntu-based distributions, inspect the Apache logs with the following command:
journalctl -u apache2.service
For CentOS, Fedora and RHEL-based distributions, inspect the Apache logs with the following command:
journalctl -u httpd.service
If your Apache server has errors in the journalctl logs, you will need to investigate Apache's configuration file.
If you have any error you receive in a browser, you will need to check Apache log files to troubleshoot and fix it.
For Debian and Ubuntu-based distributions, check the Apache log file using the following command:
tail -f /var/log/apache2/error.log
For CentOS, Fedora and RHEL-based distributions, check the Apache log file using the following command:
tail -f /var/log/httpd/error.log
Check Other Services
The Apache error may be a problem with your firewall or databases. For example, temporarily disable the firewall or check the database or system log files for more information.
This guide explained all possible ways to troubleshoot and fix common errors with Apache. I hope this will helps you to investigate and fix the errors.
How to view Apache logs?
Access the Apache log from Unix or Linux and use the var/log/log_type to view the Apache logs from the directory of /var/log/apache/access.
Why does Apache keep crashing?
If Apache is unexpectedly shutting down, there can be a configuration problem. You can tune its configuration to improve performance. Go through the Apache log: You should be able to find an error message that gives more detailed information if Apache is shutting down.
Backup one server, database, or application for free forever.
Thank you for helping us improve!