Package php5 have no installation candidate (Ubuntu 16.04)

Package php5 have no installation candidate (Ubuntu 16.04)

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

Stefan Bogdanescu

Founder & Senior Architect

Package php5 have no installation candidate (Ubuntu 16.04)

Upgrading from Ubuntu 15.10 to 16.04 (Xenial Xerus) fundamentally changed how the system handles PHP packages, leading to the error Package 'php5' has no installation candidate. This isn't a broken package manager or a missing repository; it is an intentional architectural shift by the Ubuntu project. In Debian-based distributions prior to the 16.04 era, PHP versions were bundled directly into the main repositories under versioned prefixes like php5, php7, and so on. Starting with Xenial Xerus, however, Ubuntu moved away from including major PHP releases in the default main repository structure.

When you attempt to run sudo apt-get install php5 php5-mcrypt on a fresh 16.04 installation or an upgraded system, the package manager correctly identifies that no candidate exists for the string "php5". The error message explicitly states that the package is not available but is referred to by another package. This usually implies that the functionality you need is now split across different repositories (like universe) or requires a specific versioned package name.

The Version Naming Shift

In Ubuntu 16.04 and later, the default PHP version provided in the main repositories is typically PHP 7.x. Consequently, the legacy php5 package was removed from the standard pool because maintaining multiple major versions of the same language in the base distribution became unsustainable for the upstream maintainers. The specific packages you were looking for, such as php5-mcrypt, no longer exist under that prefix.

To resolve this on Ubuntu 16.04, you must target the actual version available in the repository. Since PHP 7 is the default offering, the command to install the core interpreter and the mcrypt extension (if supported for PHP 7) changes significantly:

sudo apt-get update
sudo apt-get install php7.0 php7.0-mcrypt

It is crucial to verify if php7.0-mcrypt exists in your specific repository before running the install command, as support for certain extensions varies between PHP versions and Ubuntu releases. If you strictly require PHP 5 functionality for legacy code, simply upgrading the system does not automatically grant access to it; the package must be sourced from a third-party repository that still hosts PHP 5 builds for older LTS releases.

Accessing Legacy PHP Versions

If your application logic is tightly coupled to PHP 5 features and you cannot migrate to PHP 7 immediately, you need to add a Personal Package Archive (PPA) or use an external repository that maintains backports of older versions. Without this step, apt-get will continue to report that the package has no installation candidate because the default index only lists PHP 7.x.

One common approach for users needing older versions involves adding a PPA managed by community maintainers who curate packages for legacy compatibility. However, you must exercise caution here. Installing outdated PHP versions on an LTS release like 16.04 can introduce security risks if the upstream project has stopped issuing security patches for that specific version.

Before proceeding with custom repositories, check the status of available packages:

apt-cache policy php5
apt-cache policy php7.0

This command reveals which versions are installed, which are candidates for installation, and from which repository they originate. If php5 shows no candidates, it confirms that the default sources do not contain it.

Migration Considerations

While patching the system to install PHP 5 is possible via PPAs, the more robust engineering decision is often to refactor the application codebase to utilize PHP 7.0 or later. The performance gains in PHP 7.x are substantial, and many libraries that were once exclusive to PHP 5 have matured significantly in newer versions.

If you decide to stick with a third-party repository for PHP 5, ensure you also update your php.ini configuration files located in /etc/php/5.x/cli/ and /etc/php/5.x/apache2/ (if applicable) to match the new installation path. A common pitfall during this transition is failing to clear the APC cache or restarting the web server after installing new extensions, which results in runtime errors even though the packages are installed successfully.

The error you encountered is a direct consequence of Ubuntu's decision to streamline its package ecosystem by removing redundant legacy versions from the main index. By targeting the correct versioned package name and understanding that php5 is effectively deprecated in favor of php7.x in modern Ubuntu releases, you can resolve the installation issue without relying on unstable backports or unsupported workarounds.

Our network