Apache2 Not Starting – Troubleshooting Guide

apache-2.2PHPUbuntu

I recently was having troube getting Apache2 to work with php7.1.
I enabled the php module by using sudo a2enmod php7.1 and that worked.

I updated my server using:

sudo apt-get update

and then

sudo apt-get upgrade

After I had updated my server I restarted it.

my wordpress site was no longer working and it was just displaying the .php page as plain text again.

I assumed it was was the same issue I was having before so I manually tried to re-enable the php7.1 module again using the same command mentioned above (sudo a2enmod php7.1). After running that command I attempted to restart Apache2 with:

sudo service apache2 restart

Only to provide me with this error:

    Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

So of course I run systemctl status apache2.service to try to see what the issue was.

This is was I was provided with:

● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Mon 2018-06-25 23:54:16 CDT; 7min ago
  Process: 1163 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

Jun 25 23:54:16 UndergroundSpecInc systemd[1]: Starting The Apache HTTP Server...
Jun 25 23:54:16 UndergroundSpecInc apachectl[1163]: apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax e
Jun 25 23:54:16 UndergroundSpecInc apachectl[1163]: Action 'start' failed.
Jun 25 23:54:16 UndergroundSpecInc apachectl[1163]: The Apache error log may have more information.
Jun 25 23:54:16 UndergroundSpecInc systemd[1]: apache2.service: Control process exited, code=exited status=1
Jun 25 23:54:16 UndergroundSpecInc systemd[1]: apache2.service: Failed with result 'exit-code'.
Jun 25 23:54:16 UndergroundSpecInc systemd[1]: Failed to start The Apache HTTP Server.

So to follow the trail I investigate line 146 of /etc/apache2/apache2.conf to find this:

IncludeOptional mods-enabled/*.load

At this point I am stuck because I don't see anything wrong with that line.

Best Answer

It seems that I have answered my own question!

To fix this I had to first start by completely removing everything installed that was related to php. (This is because I have updated php a few times on this installation of Ubuntu so there were conflicts from previous versions.)

sudo apt-get purge php*

Next I found this write up that explained that on the newest version of Ubuntu (18.04) will automatically install php7.2 by just using "php" in the apt-get command. So to reinstall I simply used:

sudo apt-get update
sudo apt-get upgrade

and then once that was finished adjusting packages from purging php* I reinstalled php with this command:

sudo apt-get install php

Once that finished up I doubble checked my installation version by running:

php -v

This gave me an output that said I was running php 7.2. Great!

I still needed to reinstall the modules for php7.2 since they got removed after the purge. That was done with:

apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php

After this finished up I re-enabled the php module for Apache2 by running:

sudo an2enmod php7.2

That was successful! So the last step in makeing sure everything was running right I restarted Apache 2 with:

sudo service apache2 restart

It was a successful restart! I headed over to my browser and navigated to the php site running on that server and it loaded perfectly!

I would like to credit this site for helping out a ton!