The Ubuntu 18.04 PHP Version Limitation
You are attempting to install php8.2 on Ubuntu 18.04, but the package manager is throwing a clear error: E: Unable to locate package php8.2. This isn't a configuration mistake or a missing repository flag; it is a fundamental incompatibility between the operating system's age and the PHP version you are requesting.
Ubuntu 18.04 (Bionic Beaver), released in April 2018, shipped with PHP 7.2 as its default build. While the official Ubuntu repositories were updated to include newer versions over time, there is a hard ceiling on what can be installed directly via apt without significant manual intervention. PHP 8.2 was released in November 2022. By that point, Ubuntu 18.04 had reached its End of Standard Support (EOL) in April 2023 and entered the Extended Security Maintenance phase, which has since concluded.
When you add the OndÅej Surý PPA (ppa:ondrej/php), you are accessing a third-party repository that maintains backported versions of PHP for older Ubuntu releases. However, even this community-maintained source does not support PHP 8.2 on Bionic. The latest version available in the ondrej/php PPA for Ubuntu 18.04 is typically PHP 7.4 or, at best, early 8.0 builds depending on how far back they have ported the code. PHP 8.2 requires kernel and glibc updates that are incompatible with the base system libraries frozen in Ubuntu 18.04.
The Immediate Solution: Upgrade Your OS
The most robust solution is to upgrade your operating system. If you are running a production environment or a dedicated server, moving from Ubuntu 18.04 to Ubuntu 22.04 LTS (Jammy Jellyfish) is the standard path forward. Ubuntu 22.04 includes PHP 8.2 in its default repositories and supports the modern extensions required for current frameworks like Laravel or Symfony.
If you are running a legacy application that strictly requires Ubuntu 18.04, you are limited to the versions supported by the OndÅej Surý PPA. You can check the exact available version by running:
apt-cache madison php-fpm | grep ondrej
This command will list the specific PHP minor versions (e.g., 7.4, 8.0) that are actually present in the active package lists for your current OS version. Attempting to install a newer major version than what is listed will always result in the "Unable to locate package" error you encountered.
Containerization as an Alternative
If upgrading the host OS is not an option due to hardware constraints or legacy dependencies, containerization provides an isolation layer that bypasses the host's PHP limitations entirely. You can spin up a Docker container running Ubuntu 22.04 and install PHP 8.2 within that environment without touching the host system.
Here is a minimal example of how to set this up:
docker run -d \
--name php-fpm-82 \
-p 9000:9000 \
-v /path/to/your/app:/var/www/html \
ubuntu:22.04 \
sh -c "apt update && apt install -y software-properties-common curl unzip libpng-dev libjpeg-dev libfreetype6-dev libwebp-dev libonig-dev libzip-dev php8.2-fpm composer"
This approach allows you to maintain the old host OS while utilizing modern PHP versions and FPM pools. You would then configure your web server (Nginx or Apache) on the host to proxy requests to this container, passing the FastCGI parameters correctly.
Why Not Just Compile from Source?
You might consider compiling PHP 8.2 directly from source code on Ubuntu 18.04. While technically possible if you manage dependencies manually (such as installing a newer glibc or using containers for build tools), this is generally ill-advised for production servers. Compiling PHP introduces significant complexity regarding shared libraries, security patches, and ABI compatibility. The binary packages provided by the Ubuntu team and the OndÅej Surý PPA are pre-tested to ensure they work with the system's existing C library version.
The error you received is a protective mechanism from apt. It prevents you from installing software that would immediately fail to run or crash your server due to missing underlying dependencies. The path of least resistanceâand the most secure oneâis to align your PHP version with the supported range of your Ubuntu release, or migrate to a newer release where the desired version is natively available.