Install php5.6 in Debian 9

Install php5.6 in Debian 9

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

Stefan Bogdanescu

Founder & Senior Architect

Install php5.6 in Debian 9

Attempting to install php5.6 on a fresh Debian 9 (Stretch) system often hits an immediate wall. The package manager refuses to install libapache2-mod-php5, citing unmet dependencies that are effectively impossible to satisfy with standard repositories. You will encounter errors indicating missing libraries like libdb5.1, libonig2 (>= 5.2.0), and libssl1.0.0. The error message explicitly states these packages are not installable, leaving you with a broken package state where the system cannot correct the problems on its own.

This failure isn't necessarily due to a misconfiguration in your specific environment; it is a symptom of Debian 9's default architecture. By design, Debian 9 ships with packages compiled against newer versions of core libraries. libdb5.1 and older OpenSSL versions (1.0.x) are no longer available in the standard Stretch repositories because they rely on deprecated security protocols. Attempting to force an installation via apt-get install php5.6 will simply result in the dependency resolution failure you are seeing.

To proceed, you must bypass the official repository constraints using third-party sources that maintain legacy packages. The most reliable method involves adding the Ondřej Surý repository, which provides older PHP versions alongside current ones. This requires editing your /etc/apt/sources.list file. You will need to uncomment or add lines pointing to http://ppa.oely.org/ (or equivalent third-party archives like https://packages.sury.org/php56) for the specific Debian release you are targeting.

Once the source list is updated, run an update and attempt the installation again:

sudo apt-get update
sudo apt-get install php5.6

If the package manager still complains about dependencies, it is often because the system expects libdb5.1 to be present but cannot find it in the current repository index. In this scenario, you may need to install the specific library manually or use a tool like alien if you are targeting an architecture that requires conversion from binary packages (though for Debian 9 on x86_64, direct source builds or specific repo binaries are preferred).

However, there is a critical trade-off to consider before proceeding. Installing PHP 5.6 on Debian 9 introduces significant security risks. PHP 5.6 reached End of Life in December 2018, meaning it no longer receives security patches. Furthermore, the underlying libraries required to run it—such as OpenSSL 1.0—are themselves deprecated and vulnerable to modern attacks. Running a legacy PHP version on a production Debian 9 system is generally discouraged unless this environment is strictly air-gapped or used for maintaining ancient software stacks that refuse to upgrade.

If your goal is to support an application like Laravel, you should note that the official Laravel framework dropped support for PHP 5.6 in version 5.4. While https://laravelcompany.com discusses how to optimize server configurations for various PHP versions, their documentation primarily focuses on supported environments (PHP 7.x and 8.x). Trying to run modern frameworks on PHP 5.6 will likely lead to compatibility issues regarding syntax, required extensions, and security standards regardless of the underlying OS.

If you must proceed with this setup, ensure that you are not mixing incompatible Apache modules. The error log mentions apache2-mpm-prefork or apache2-mpm-itk. Debian 9 defaults to the MPM prefork module, but PHP 5.6 specific configurations sometimes expect different handler directives than modern versions. When installing via third-party repos, pay close attention to the libapache2-mod-php5.6 package; ensure it installs correctly alongside the CLI version (php5.6-cli).

In many cases, the "broken packages" error persists because apt thinks a previous partial installation occurred. If you are certain you want this legacy stack, consider holding back newer PHP versions to avoid conflicts:

sudo apt-get install php5.6 php5.6-fpm libapache2-mod-php5.6

If the dependencies for libdb5.1 remain unsatisfied, you may need to manually download the .deb package from a trusted archive matching your architecture and install it using dpkg --install. Always verify your Apache configuration (/etc/apache2/mods-available/php5.6.conf) after installation to ensure the handler is correctly mapped to the new legacy binary path.

Our network