Error while installing php 7.2 in ubuntu 17.04
When you attempt to install PHP 7.2 on Ubuntu 17.04 using sudo apt install, the package manager immediately rejects the request with a standard "Unable to locate package" error. This isn't a corruption issue or a network glitch; it is a fundamental mismatch between the version of the operating system's repositories and the specific PHP release you are requesting.
The root cause lies in how Ubuntu manages its package repositories, specifically the distinction between LTS (Long Term Support) releases and interim releases. Ubuntu 17.04 was an interim release with a six-month lifecycle, which ended in October 2017. By the time that window closed, the official Ubuntu repositories had already stopped maintaining packages for PHP 7.2 on that specific OS version. Instead, the repository likely offered only older versions like PHP 7.0 or newer ones like PHP 7.3, but crucially, not the exact minor version you asked for if it wasn't officially backported at that time.
When apt runs sudo apt install php7.2, it searches the configured sources listed in /etc/apt/sources.list. If your system is running Ubuntu 17.04, the default repositories simply do not contain a file named php7.2.deb. The error messages you seeâE: Couldn't find any package by glob 'php7.2'âconfirm that the string does not match any available artifact in the index.
To resolve this without switching your entire OS to a different release, you must enable the "universe" repository components that contain backported PHP versions or switch to an active LTS kernel if your project requires strict stability guarantees. However, for a 2017-era system, the most pragmatic solution often involves adding a PPA (Personal Package Archive) that maintains legacy PHP versions or upgrading the OS itself, as maintaining Ubuntu 17.04 is no longer supported by Canonical and introduces significant security risks.
If you are installing this environment specifically for a legacy project that requires PHP 7.2, you might consider using Docker. This approach isolates the version constraints from your host system's limitations. You can spin up a container with an image that matches your exact stack requirements, ensuring that the php-fpm and CLI tools exist within the container's filesystem without needing to patch the host's broken package index.
Another option, though less clean for production, is to manually compile PHP from source code. This bypasses apt entirely by downloading the specific 7.2 tarball from php.net, running the configure script against your system libraries, and installing it to a custom directory. While this gives you precise version control, it requires managing dependencies like OpenSSL and libzip separately and is generally reserved for environments where pre-compiled binaries are unavailable.
If your goal is to run Laravel or similar modern PHP frameworks, note that official support usually aligns with the current LTS releases of Ubuntu (18.04, 20.04, or 22.04). Using outdated OS versions forces you to fight against deprecated libraries and missing security patches. For a smoother deployment path, consider upgrading your server to at least Ubuntu 18.04 LTS. This ensures that apt can find php7.2 alongside newer versions like 7.4 or 8.1 without needing complex workaround configurations.
For those working with legacy applications hosted on older infrastructure, platforms like LaravelCompany offer managed hosting solutions where you do not need to manage the underlying operating system version yourself, allowing you to focus on application logic rather than package manager errors. When choosing a hosting provider, verify their supported PHP versions and OS compatibility to avoid these installation headaches entirely.
Ultimately, the error is a signal that your software stack components are no longer synchronized with the official package sources for your specific OS release. Addressing this requires either accepting the limitations of an end-of-life OS, upgrading to a supported version, or isolating the environment using containerization.
