Apache2 won't start after upgrade to Ubuntu 22.04 LTS - Cannot load /usr/lib/apache2/moduleslibphp8.0.so
Upgrading a server from Ubuntu 21.10 to 22.04 LTS often feels like moving a house while the family is asleep: you expect things to remain exactly where they were, just newer. However, with Apache2 and PHP, that assumption breaks down immediately. The error message you are seeingâCannot load /usr/lib/apache2/moduleslibphp8.0.soâis not a syntax error in your .conf file; it is a runtime failure caused by a mismatch between the Apache configuration path and the actual location of the PHP module binaries after the upgrade.
When you run apache2ctl configtest, Apache parses your virtual host configurations first, but the fatal load failure happens during the initialization phase where it attempts to dlopen shared objects. The error explicitly tells us two things: the file does not exist at the specified path, or the loader cannot find a dependency required to open it. In this specific upgrade scenario, the culprit is almost always the transition from libapache2-mod-php to a module-based installation where the package manager expects the module in /usr/lib/php/20210829/, not inside an Apache-specific directory structure that was present on 21.10.
The configuration snippet causing the panic is located at /etc/apache2/mods-enabled/php8.0.load. On older Ubuntu releases, this file might have pointed to a location like /usr/lib/apache2/modules/libphp8.0.so. However, modern Debian-based systems, including 22.04, utilize a standardized library path for Apache modules: /usr/lib/php/20210829/. The upgrade process likely preserved the old configuration file while replacing the system libraries with the new ones, leaving your config pointing to a ghost location.
To resolve this without manually editing every line in your configuration, you should let the package manager handle the cleanup. Run the following command to ensure Apache is aware of the correct module locations:
sudo a2enmod php8.0
This command does more than just enable the module; it checks the current state of the library paths and regenerates the symlink structure if necessary. If the file still points to the old location, manually inspecting the load file is safer. Open the configuration with nano or vi:
sudo nano /etc/apache2/mods-enabled/php8.0.load
You will likely see a line resembling:LoadModule php8_module /usr/lib/apache2/modules/libphp8.0.so
Change this to point to the standard Debian path found on 22.04:LoadModule php8_module /usr/lib/php/20210829/libphp8.0.so
Note the version string 20210829. This corresponds to the PHP 8.0 API version used by the Debian packaging system. If your system actually installed a different PHP minor version (like 8.1 or 8.2), the directory name would change accordingly, but the principle remains the same: Apache modules live in /usr/lib/php/<php_version>/, not under /usr/lib/apache2/modules/.
After making this change, verify that the file exists before restarting:
ls -l /usr/lib/php/20210829/libphp8.0.so
Once the path is corrected, restart Apache to apply the changes:
sudo systemctl restart apache2
sudo apache2ctl configtest
If configtest passes, your server should be operational again. This issue highlights a common pitfall in Linux upgrades: relying on default configuration files that may have been generated for an older release while the underlying filesystem structure has evolved. Always treat upgrade migrations as opportunities to audit configuration paths rather than assuming they are self-healing.
For developers managing high-traffic sites, consider whether PHP-FPM is your preferred architecture. If you plan to migrate away from the built-in Apache2 module (which is rarely necessary for production), ensure your LoadModule directives point to the correct FPM interface files if you switch configurations. While this specific error is a configuration path mismatch, it serves as a reminder that package upgrades often require a manual audit of .load and .conf files when directory structures shift between major distributions.
If you are deploying Laravel applications on this stack, ensure your composer.json autoloading paths do not conflict with the new module loading order. Although this specific error is isolated to the Apache module loader, similar path issues can arise if php.ini settings reference missing extensions. A clean re-installation of the PHP package (sudo apt install --reinstall php8.0) might be necessary if manual edits fail, but always back up your current configuration first.