Failed to start apache2.server

Failed to start apache2.server (while booting or otherwise)


    sudo systemctl status apache2    

results in the following message:

× apache2.service - The Apache HTTP Server 
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled
     Active: failed (Result: exit-code) since Fri 2025-08-29 08:17:06 IST; 1h 33min ago
       Docs: https://httpd.apache.org/docs/2.4/
        CPU: 95ms

Aug 29 08:17:02 mfcarlo-HP-Pavilion-dv6-Notebook-PC systemd[1]: Starting apache2.server - The Apache HTTP Server...
Aug 29 08:17:06 mfcarlo-HP-Pavilion-dv6-Notebook-PC apachectl[1768]: apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 3 of /etc/apache2/mods-enabled/php8.1.load: Cannot load /usr/lib/apache2/modules/libphp8.1.so into server: /usr/lib/apache2/modules/libphp8.1.so: cannot open shared object file: No such file or directory
Aug 29 08:17:06 mfcarlo-HP-Pavilion-dv6-Notebook-PC systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Aug 29 08:17:06 mfcarlo-HP-Pavilion-dv6-Notebook-PC systemd[1]: apache2.service: Failed with result 'exit-code'.
Aug 29 08:17:06 mfcarlo-HP-Pavilion-dv6-Notebook-PC systemd[1]: Failed to start apache2.service - The Apache HTTP Server.

So, first install the latest PHP:

    sudo apt install libapache2-mod-php    

You might see the following (similar) trailing error message:

apache2_reload: Your configuration is broken. Not restarting Apache 2
apache2_reload: apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: 
Syntax error on line 3 of /etc/apache2/mods-enabled/php8.1.load: Cannot load /us
r/lib/apache2/modules/libphp8.1.so into server: /usr/lib/apache2/modules/libphp8
.1.so: cannot open shared object file: No such file or directory

But you should still be able to locate similar files at the following (similar) paths:

/usr/lib/apache2/modules/libphp8.3.so
/etc/apache2/mods-available/php8.3.load
/etc/apache2/mods-available/php8.3.conf
/etc/apache2/mods-available/php8.1.load
/etc/apache2/mods-available/php8.1.conf

Note that 8.3 is the latest PHP version at the time of this writing. It could be a different version in your case.
Also, 8.1 was the current PHP version on my computer, prior to this update. It could be a different version in your case (based on your error message).

    sudo a2dismod php8.1             
    sudo a2enmod php8.3              
    sudo systemctl restart apache2   
    sudo systemctl status apache2    

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled
     Active: active (running) since Fri 2025-08-29 10:36:06 IST; 27s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 91727 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS
   Main PID: 91730 (apache2)
      Tasks: 6 (limit: 9380)
     Memory: 14.0M (peak: 14.7M)
        CPU: 81ms
     CGroup: /system.slice/apache2.service
             ├─91730 /usr/sbin/apache2 -k start
             ├─91739 /usr/sbin/apache2 -k start
             ├─91740 /usr/sbin/apache2 -k start
             ├─91741 /usr/sbin/apache2 -k start
             ├─91742 /usr/sbin/apache2 -k start
             └─91743 /usr/sbin/apache2 -k start

Aug 29 10:36:06 mfcarlo-HP-Pavilion-dv6-Notebook-PC systemd[1]: Starting apache2.service - The Apache HTTP Server...
Aug 29 10:36:06 mfcarlo-HP-Pavilion-dv6-Notebook-PC apachectl[91729]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Aug 29 10:36:06 mfcarlo-HP-Pavilion-dv6-Notebook-PC systemd[1]: Started apache2.service - The Apache HTTP Server.

To suppress the following warning message:

Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

Edit the configuration file in privilege mode:

sudo gedit /etc/apache2/apache2.conf

Uncomment the following line if it already exists or append a new one:

    ServerName localhost    

Restart Apache and recheck its status:

    sudo systemctl restart apache2   
    sudo systemctl status apache2    

The warning message should disappear.
Furthermore, perform a configuration test to verify that all is well.

    sudo apachectl configtest    

It should normally output the following message:

Syntax OK

Comments

Popular posts from this blog

Bluetooth Error: obex connect failed with 0x53

Decrypting PGP-encrypted messages