Fixing-Unable to start service apache2 Job for apache2.service failed because the control process exited with error code?

Many companies utilize the well-known open-source web server Apache2 to host websites and applications. You might experience a problem where the service cannot be started and you see an error message like "Unable to start service apache2: Job for apache2.service failed because the control process exited with error code".

Whether you are installing Apache2 manually or using Ansible to automate the process. I will walk you through the troubleshooting procedures to resolve this issue in this post.

Here are some screenshots I have taken when I was trying to start Apache2 Service -

Ansible Playbook failed to start Apache2 service

Unable to start service apache2 with Ansible playbook

Manually starting Apache2 service also failed

Unable to start service apache2 even manually using systemctl start apache2

In this article, we will guide you through the troubleshooting steps to fix this issue.

1. Check any port conflicts

Conflicting ports can also prevent the Apache2 service from starting and it is one of the most common issue

To find processes utilizing the same port as Apache2, use the netstat -tlnp | grep ":80" command.

If there is a conflict, you may either terminate the infringing service or modify the configuration files to alter the port that Apache2 uses.

Here is the screenshot where I am checking if there is any process which has already occupied the port 80 -

Check for any port conflicts using netstat command

Solution -

  1. Kill the process running on the port using the command kill -9 <process-id>
  2. Update the apache config located /etc/apache2/apache2.conf and assign different port for the apache2 service.

2. Check the Apache2 Error Log

When the Apache2 service fails to start, the second place to look is the error log file located at /var/log/apache2/error.log.

Check the log for any error messages that may indicate the cause of the failure.


3. Validate apache2.conf for Configuration Errors

If the configuration files include mistakes, the Apache2 service can be unable to start.

To examine the configuration files for syntax issues, use the apachectl configtest command. The configuration files can be edited to correct any issues.

If you apache2.conf is correct then you should see following message -

Validate apache2.conf for any configuration error


4. Start the Server again

Starting-service problems can occasionally be resolved by simply restarting the server.

Here is the command to restart the apache2 service -

1sudo systemctl restart apache2 

5. Install Apache2 again

You might need to reinstall Apache2 if the aforementioned solutions don't resolve the problem.

You may uninstall the program with the command -

1sudo apt-get remove apache2 

After remove the apache2 you can reinstall it with the command -

1sudo apt-get install apache2 

Conclusion

Although setting up and operating Apache2 might be simple, problems can arise if the service doesn't start.

You may use the troubleshooting instructions in this article to help you resolve the "Unable to start service apache2: Job for apache2.service failed because the control process exited with error code" fault while installing Apache2 manually or using Ansible.

You should be able to set up Apache2 quickly by following these instructions.

Posts in this series