Unable to locate package libapache2-mod-php7

Unable to locate package libapache2-mod-php7

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Unable to locate package libapache2-mod-php7

When you attempt to install PHP modules on an older Ubuntu release like 16.04, it is common to encounter a package that no longer exists in your repository. The error message Unable to locate package libapache2-mod-php7 is not a bug; it is a signal that the version number has changed or the package naming convention was updated between releases.

In Ubuntu 16.04 (Xenial Xerus), the Apache module for PHP 7 is actually named libapache2-mod-php70, not libapache2-mod-php7. The command you provided attempts to fetch a package that does not exist in the default repositories. If you run sudo apt-get install libapache2-mod-php70 instead, the installation should proceed without errors. However, relying on the specific version number 70 ties your configuration strictly to Ubuntu 16.04.

Why Package Names Changed

Ubuntu and Debian-based distributions frequently update their package naming schemes to reflect the current upstream state of software. Early versions of PHP 7 were often referred to simply as "PHP 7," but once PHP 8 arrived, the distinction became critical. To avoid ambiguity, maintainers renamed packages from php7 to php74 (and later php82, etc.), and similarly updated the Apache modules to libapache2-mod-php70.

If you are working within an LAMP stack on 16.04, skipping the module entirely will prevent Apache from executing PHP scripts. Without the module, requests to .php files will return a "500 Internal Server Error" or simply display the raw source code because the server lacks the interpreter.

Installation and Configuration Steps

To resolve this issue correctly on Ubuntu 16.04, you need to ensure that your package lists are updated before attempting installation. Run the following commands in sequence:

sudo apt-get update
sudo apt-get install libapache2-mod-php70 php7.0-mysql php7.0-curl php7.0-json php7.0-fpm

Note that php7.0-cgi is generally not recommended for production web servers. Instead, the industry standard is to use PHP-FPM (FastCGI Process Manager) or the Apache module directly. If you choose the Apache module (libapache2-mod-php70), Apache loads the module and handles requests directly. If you prefer PHP-FPM, you would typically run Apache in front of Nginx, or configure Apache to proxy PHP requests using proxy_fcgi_module.

Once the packages are installed, you must ensure that the Apache configuration file for PHP exists. On Ubuntu 16.04, this is usually located at /etc/apache2/mods-available/php7.conf (or sometimes named with the version suffix). If the file is missing or commented out, enable it manually:

sudo a2enmod php7
sudo systemctl restart apache2

If you are on a newer Ubuntu version (18.04 LTS or later), this package name will be different entirely. On 18.04 and 20.04, the module is typically named libapache2-mod-php7.2 or libapache2-mod-php8.0, depending on which PHP version you installed via the official repos. Always check the output of dpkg -l | grep php to verify which specific module names are present in your current environment before running install commands.

Trade-offs and Modern Alternatives

While fixing this specific error is straightforward, it highlights a broader issue: Ubuntu 16.04 reached End of Life (EOL) in April 2021. Security updates for the default repositories were discontinued at that point. Continuing to run production applications on EOL OS versions introduces significant security risks and compatibility issues with modern PHP extensions.

If you are starting a new project, consider upgrading to Ubuntu 20.04 or 22.04 LTS. These versions support current PHP releases (8.x) out of the box, eliminating the need for manual version mapping like libapache2-mod-php70.

For developers using Laravel, running on an EOL OS can cause friction with Composer dependencies and security hardening requirements. While you might find legacy tutorials referencing old package names, modern best practices dictate using supported environments. If your infrastructure relies on older systems, ensure that you have a plan to migrate away from EOL platforms rather than patching the underlying OS indefinitely.

In summary, simply changing libapache2-mod-php7 to libapache2-mod-php70 resolves the immediate installation error on Ubuntu 16.04. However, the long-term solution involves upgrading your operating system to a supported release to ensure security and access to modern PHP features.

Our network