creative dark internet designer

[SOLVED] HOW TO START APACHE SERVER? Apache2.service Failed with result ‘exit-code’.

ERROR: APACHE2.SERVICE FAILED WITH RESULT ‘EXIT-CODE’.

This blog is a quick fix for running apache service via your terminal. There could be several reasons for apache server to be dysfunctional. The error trace is something like this:

‚óŹ apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2022-01-07 17:36:35 +0545; 2min 10s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 212815 ExecStart=/usr/sbin/apachectl start (code=exited, status=139)
systemd[1]: Starting The Apache HTTP Server...
apachectl[212833]: AH00558: apache2: Could not reliably determine the s>
apachectl[212815]: Segmentation fault (core dumped)
apachectl[212815]: Action 'start' failed.
apachectl[212815]: The Apache error log may have more information.
systemd[1]: apache2.service: Control process exited, code=exited, statu>
systemd[1]: apache2.service: Failed with result 'exit-code
systemd[1]: Failed to start The Apache HTTP Server.

CAUSE: Conflict with Multiple PHP Versions

The reason for Apache server now working on my workstation was due to the version conflict in PHP. MIstakenly I enabled both apache2 modules of PHP while trying to switch from PHP7.3 to PHP8.0. You can see which modules are enabled by running this command in your teminal:

ls -l mods-*/*php*
root root 867   19 12:24 mods-available/php5.6.conf
root root 102   19 12:24 mods-available/php5.6.load
root root 855   19 12:10 mods-available/php7.3.conf
root root 102   19 12:10 mods-available/php7.3.load
root root 855   31  2020 mods-available/php7.4.conf
root root 102   31  2020 mods-available/php7.4.load
root root 855  21 03:07 mods-available/php8.0.conf
root root 101  21 03:07 mods-available/php8.0.load
root root  29    7 17:20 mods-enabled/php7.3.conf -> ../mods-available/php7.3.conf
root root  29    7 17:20 mods-enabled/php7.3.load -> ../mods-available/php7.3.load
root root  29    7 17:36 mods-enabled/php8.0.conf -> ../mods-available/php8.0.conf
root root  29    7 17:36 mods-enabled/php8.0.load -> ../mods-available/php8.0.load

You can see the modules for php7.3 and php8.0 both are enabled. Due to this conflict systemctl command couldn’t restart apache2 service

SOLUTION: Disable one of the PHP Module

The solution is quite straight forward. Among the two php modules, disable one and keep only one php running. In your terminal disable php module by running following command:

sudo s2dismod php8.0
# And restart apache2 
sudo systemctl restart apache2

Now if you check which modules are enabled you will see the output like shown below:

s -l mods-*/*php*
root root 867   19 12:24 mods-available/php5.6.conf
root root 102   19 12:24 mods-available/php5.6.load
root root 855   19 12:10 mods-available/php7.3.conf
root root 102   19 12:10 mods-available/php7.3.load
root root 855   31  2020 mods-available/php7.4.conf
root root 102   31  2020 mods-available/php7.4.load
root root 855  21 03:07 mods-available/php8.0.conf
root root 101  21 03:07 mods-available/php8.0.load
root root  29    7 17:20 mods-enabled/php7.3.conf -> ../mods-available/php7.3.conf
root root  29    7 17:20 mods-enabled/php7.3.load -> ../mods-available/php7.3.load

Your APache server should be now up and running.