13

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

8 Answers 8

21

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.

2
  • In my case, I found only libphp7.3.so. Commented Oct 16, 2018 at 16:01
  • 2
    Correct way to fix this is Audrius' solution below.
    – user5849541
    Commented May 9, 2020 at 16:27
20

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
1
  • 7.4 to 8.1 in my case, thanks
    – bcag2
    Commented Mar 27, 2023 at 11:58
7

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!

5

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
1
2

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)

0

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
3
  • 1
    Hi @eugho, welcome to Stackoverflow! It's great that you want to contribute and share your knowledge. Please note: Before answering, please read the question carefully. You will notice that the original poster has a completely different error than you describe in your answer. Your error is "No such file or directory" while their error is "Syntax error on line 140 of /etc/apache2/apache2.conf". (Not trying to be a dick here, just trying to help you improve).
    – Stefan
    Commented Apr 26, 2020 at 9:17
  • 1
    Hi @Stefan, please take a look at the answer given by the poster himself. He did add-on with additional error logs that matches the errors I have provided.
    – brigzz
    Commented Apr 27, 2020 at 10:33
  • Hi @eugho, sorry, the Stackoverflows review-UI only asked me to review your answer, so I didn't see anything else. :) In any case, I would really ask you to make yourself familiar with the posting-guidelines for good answers:meta.stackexchange.com/questions/118582/… -- Which category do you think your answer falls into? :) -- Stay safe!
    – Stefan
    Commented Apr 27, 2020 at 11:33
0

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.

0

I used a variation of this solution where I just went into /etc/apache2/mods-enabled and symbolically linked ../mods-available/php8.1.load to php8.1.load and ../mods-available/php8.1.conf to php8.1.conf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.