menu

Questions & Answers

Apache2 won't start after upgrade to Ubuntu 22.04 LTS - Cannot load /usr/lib/apache2/moduleslibphp8.0.so

I am a bit stuck as to how to fix this. I did a distro upgrade a server running Apache2.

Since the upgrade it has not worked. I ran a config test and below is the error. I had no issues with my configuration on the previous version of Ubuntu (21.10)

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

Any ideas where to begin? I'm still fairly inexperienced when it comes to Apache.

Comments:
2023-01-24 00:10:03
did you run sudo "apt-get update && sudo apt-get upgrade" after upgrading?
2023-01-24 00:10:03
I sure did. Thank you. Not sure why the mod config didn't just update itself. Pretty sure it normally does right?
2023-01-24 00:10:03
no all the time, some are disabled depending on how you upgrade. We have alot of php 5.3 stuff so we have it disabled so we can continue running. But some packages don't support it or won't. Its a bit of a maze unfortunately but the easiest way is to check what has been updated
Answers(6) :

While you've figured this out, others will come (like myself) to see how you did this.

# perhaps you did the following to see what modules were present
> apache2ctl -M

# the result of the above command may have returned an error such as:
apache2:
 Syntax error on line 146 of /etc/apache2/apache2.conf:
  Syntax error on line 2 of /etc/apache2/mods-enabled/php8.0.load:
   Cannot load /usr/lib/apache2/modules/libphp8.0.so into server:
    /usr/lib/apache2/modules/libphp8.0.so:
     cannot open shared object file: No such file or directory
Action '-M' failed.

# so you removed the problematic module that was no longer installed
# by doing the following (as appropriate given the error above)
> sudo a2dismod php8.0

# you needed to restart your server after that
> sudo systemctl restart apache2

# if you tested the server in a browser html should function...
# however you perhaps desired the use of another php module
# and added another one (8.1) that is install by default in Ubuntu 22.04
> sudo a2enmod php8.1

# you restarted apache again and it worked?
> sudo systemctl restart apache2

Perhaps you were using mod_userdir and also needed to update the apache php module configuration file:

/etc/apache2/mods-enabled/php8.1.conf

By commenting out the following lines:

<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>

So that they looked like this:

#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_flag engine Off
#    </Directory>
#</IfModule>
# finally you restarted apache2 again:
sudo systemctl restart apache2
# and everything was back to normal?

Did you do something like this?

Comments:
2023-01-24 00:10:03
Thanks for the detailed answer. Haven't touched apache in a long while and this got me straight to working again.
2023-01-24 00:10:03
Thank you very much!!! After upgrading from 21.10 to 22.04 got the same problem as the OP. Your help is great!!!!!!

In my case I upgraded Ubuntu 20.04 to 22.04. So the wizard uninstalled the php7.4 modules and installed php8.1 modules instead. After that I tried to restart apache2 but it didn't. I realized that in my /etc/apache2/mods-enabled folder I still had php7.4.conf and php7.4.load and php7.4.load was still pointing to libphp7.4.so.

Remember that mods-enabled folder is generated from mods-available folder so you should never alter mods-enabled folder. Instead, you should disable php7.4 modules:

sudo a2dismod php7.4

and enable php8.1 modules:

sudo a2enmod php8.1

Of course after enabling php8.1 modules you have to restart apache2 service.

sudo systemctl restart apache2
Comments:
2023-01-24 00:10:03
This was my case too. Thanks for mentions a2dismod and a2enmod
sudo gedit /etc/apache2/mods-enabled/php8.0.load

and rename:

LoadModule php_module /usr/lib/apache2/modules/libphp8.0.so

to:

LoadModule php_module /usr/lib/apache2/modules/libphp8.1.so

I removed (purge) php and apache2 and reinstalled. It is easier than hit-and-miss and go through hundreds of forum messages and error messages from the system.

Now it works. between 7.4 and 8.1 there has been so many changes, that most of my web pages are now broken and I have to debug them.

Disregard everyone. I figured it out.

I checked /usr/lib/apache2/modules/ and found that libphp8.0.so had been updated to libphp8.1.so.

After amending the mods-enabled to include this file and not the problematic one, apache started with no issues.

Comments:
2023-01-24 00:10:04
Welcome to stackoverflow! Thanks for the question - I had the same problem.

The OS upgrade to Ubuntu 22 updates the installed php 7.x to php8.x but it does not fix the Apache2 configurations

sudo a2dismod php7.4

sudo a2enmod php8.1

sudo a2disconf php7.4-fpm

sudo a2enconf php8.1-fpm

sudo systemctl reload apache2