SnapShooter Learning Center

How to Troubleshoot and Fix Common Problems with Apache

How to Troubleshoot and Fix Common Problems with Apache

Simon Bennett]
Simon Bennett
Last Updated: Sep 28, 2021
Table of Contents

# Introduction

Apache is a free, open-source and highly customizable software for hosting websites now a day. It is very simple and easy to install, but it is possible to run Apache into a problem. It has different configurations and settings in many places so sometimes it can be very difficult 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.

In this post, we will show you how to troubleshoot and fix Apache errors.


# Check Whether the Apache Service is Running

The first step to troubleshoot the Apache server is to make sure the Apache service is running and able to function.

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 

Or

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 error.


# Check Apache Server Configuration

Apache provides some handy tools to check the Apache server for any configuration error.

For Debian and Ubuntu-based distributions, check the Apache for any configuration error with the following command:

apache2ctl -t

For CentOS, Fedora and RHEL based distributions, check the Apache for any configuration error with the following command:

httpd -t

If everything is fine, you should get the following output:

Syntax OK

If there is an error in your Apache configuration, you should get the following output with 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 displays logs from startup to shutdown, along with any process errors that may be 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 then you will need to investigate the Apache's configuration file.

If you have any error that you receive in a browser then 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

Iahe Apre ache error then it may be a problem with your firewall or databases. You can temporary disable the firewall or check the database or system log files for more information.


# Conclusion

In this guide, we explained all possible ways to troubleshoot and fix common errors with Apache. I hope this will defin-tely helps you to investigate and fix the error.s


Did you find this article helpful?