10
votes

Ok, so, I'm fairly new to Apache: I was trying to create a local website (created the .conf file in sites-available folder, created the folder in var/www/mysite/ etc.) then, I stopped Apache (with systemctl stop apache2.service) but now if I try to restart (systemctl restart apache2.service) it throws 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.

This is the result of journalctl -xe:

Mar 22 16:33:13 user-xxx apache2[10403]:  * Starting Apache httpd web server apach
Mar 22 16:33:13 user-xxx apache2[10403]:  *
Mar 22 16:33:13 user-xxx apache2[10403]:  * The apache2 configtest failed.
Mar 22 16:33:13 user-xxx apache2[10403]: Output of config test was:
Mar 22 16:33:13 user-xxx apache2[10403]: apache2: Syntax error on line 140 of /etc/apache2/apache2.conf:
Mar 22 16:33:13 user-xxx apache2[10403]: Action 'configtest' failed.

And the line 140 in /etc/apache2/apache2.conf:

# Include module configuration:
IncludeOptional mods-enabled/*.load <--This one
IncludeOptional mods-enabled/*.conf

So I tried:

sudo apt-get install libapache2-mod-php

And I get:

libapache2-mod-php is already the newest version (1:7.2+60+ubuntu16.04.1+deb.sury.org+1).

What else I tried: removing Apache and installing again, installing lamp (sudo apt-get install lamp-server^). I already removed: mysite.conf from available.sites ...

Nothing seems to make it work, I keep getting "Job for apache2.service failed".

7

7 Answers

18
votes

after ubuntu update to 20.04 I changed PHP to 7.4

sudo a2dismod php7.3
sudo a2enmod php7.4
sudo apachectl configtest
sudo systemctl restart apache2
15
votes

Ok, kind of a dumb error, I ran apachectl configtest to get more detailed error and I got:

apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax 
error on line 3 of /etc/apache2/mods-enabled/php7.0.load: Cannot load 
/usr/lib/apache2/modules/libphp7.0.so into server: 
/usr/lib/apache2/modules/libphp7.0.so: cannot open shared object file: 
No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.

So I checked /etc/apache2/mods-enabled/php7.0.load and at line 3 it had:

LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so

But in my /usr/lib/apache2/modules folder I had a newer module:

libphp7.2.so

So In /etc/apache2/mods-enabled/php7.0.load I changed it to:

LoadModule php7_module /usr/lib/apache2/modules/libphp7.2.so

Then restarted apache and it's working like a charm!!!.

Note: I don't know if this is the correct way to do this but, it's working.

6
votes

In my case failure happened when upgrading to Ubuntu 20.04 LTS. Module libphp7.2.so instead of libphp7.4.so was loaded in conf file Melesio Marquez's solution worked!

2
votes

You can check your PHP version from here ->

php -v

then write this command

sudo a2dismod php7.3

You should see that Module php7.3 disabled. To activate the new configuration, you need to run:

systemctl restart apache2

If you want to sure check your confs

apache2ctl configtest

You should see (Syntax OK) and finally, restart your apache server (sudo systemctl restart apache2)

1
votes

I faced the error:

Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/

after upgrading from Ubuntu 18.04 to 20.04 (php 7.3 to php 7.4)

I solved it by running

sudo apt install libapache2-mod-php7.4
0
votes

The files in /etc/apache2/mods-enabled/ are symlinks to /etc/apache2/mods-available/* So just remove them and create new ones. To create a symlink at /usr/bin/bar which references the original file /opt/foo, use: ln -s /opt/foo /usr/bin/bar

To fix

cd /etc/apache2/mods-enabled/
rm php7.*
sudo ln -s /etc/apache2/mods-available/php7.4.load php7.4.load
sudo ln -s /etc/apache2/mods-available/php7.4.conf php7.4.conf

Make sure the files exist and the old links are removed. Editing the symlinks will result in upgrade issues in the future.

-1
votes

Had the same issue on Ubuntu 20.04:

Syntax error on line 146 of /etc/apache2/apache2.conf: 
Syntax error on line 3 of /etc/apache2/mods-enabled/php7.3.load: 
Cannot load /usr/lib/apache2/modules/libphp7.3.so into server: /usr/lib/apache2/modules/libphp7.3.so: 
cannot open shared object file: No such file or directory

Updated /etc/apache2/mods-enabled/php7.3.load to point to libphp7.4.so:

#LoadModule php7_module /usr/lib/apache2/modules/libphp7.3.so
LoadModule php7_module /usr/lib/apache2/modules/libphp7.4.so