Search code examples
apacheconfigurationlinux-mint

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


Solution

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