Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache not starting in linux mint

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

like image 648
Melesio Marquez Avatar asked Mar 22 '18 23:03

Melesio Marquez


4 Answers

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.

like image 127
Melesio Marquez Avatar answered Nov 20 '22 21:11

Melesio Marquez


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
like image 32
Audrius Avatar answered Nov 20 '22 20:11

Audrius


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!

like image 6
Khalil Khoury Avatar answered Nov 20 '22 20:11

Khalil Khoury


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
like image 4
Moses J Avatar answered Nov 20 '22 21:11

Moses J