PHP Version Conflict on Ubuntu 22.04 Web Server
Your company runs a customer portal on Ubuntu Server 22.04 (2 GB RAM, 2 vCPU). The application vendor now requires PHP 8.2, but the distribution repository provides PHP 8.1. Running apt install php8.2 fails with E: Unable to locate package php8.2. The server has outbound HTTPS access but no staging environment. The admin suggests adding the ondrej/php PPA, installing PHP 8.2, and removing PHP 8.1. Another admin wants to compile PHP 8.2 from source to avoid third-party repositories. The portal must stay online; a maintenance window of 30 minutes is available next Sunday. You must decide the safest path that still receives security updates.
1. Compare the PPA, compiling from source, and upgrading the OS. Which do you recommend and why?
Read the worked answer
PPA: fastest, keeps apt tracking dependencies and updates; risk is trusting a third-party maintainer and possible conflicts with distro packages. Compiling from source: avoids third-party repo but loses automatic security updates; you must track CVEs and rebuild manually, which is risky for a production portal. OS upgrade: may provide a newer PHP, but it is a large change with more downtime and regression risk. Recommendation: use the PPA if it is the official community source for PHP packages, pin it, and test in the 30-minute window with a rollback snapshot. Better still, if the app can run in a container, use a supported PHP 8.2 image. For this server, the PPA is the pragmatic choice.
Steps: apt update, apt install software-properties-common, add-apt-repository ppa:ondrej/php, apt update, apt install php8.2-fpm php8.2-cli php8.2-mysql php8.2-curl php8.2-mbstring. Check apt-cache policy php8.2.
2. Give the concrete commands to add the PPA, install PHP 8.2, and ensure the system prefers it over 8.1. What could go wrong during the switch?
Read the worked answer
Commands:
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2-fpm php8.2-cli php8.2-mysql php8.2-curl php8.2-mbstring
sudo systemctl disable --now php8.1-fpm
Update Nginx to use fastcgi_pass unix:/run/php/php8.2-fpm.sock; and reload Nginx. Validate with php -v and php -m. To pin, create /etc/apt/preferences.d/php with Package: php8.2* Pin: release o=LP-PPA-ondrej-php Pin-Priority: 1001.
What can go wrong: missing PHP extensions for the app, Nginx still pointing at 8.1 socket, session directory permissions, opcache settings, and dependency conflicts with distro PHP packages. Keep the old FPM service stopped but packages installed for rollback.
3. How would you verify that the new PHP version is active and that security updates will still arrive, and what is your rollback plan?
Read the worked answer
Verify active version: php -v, php -m, systemctl status php8.2-fpm, and a web request that prints phpinfo() or curl -I https://portal.example.com and check the X-Powered-By header. Ensure unattended-upgrades includes the PPA or run apt list --upgradable regularly. Security updates: check that the PPA publishes updates and subscribe to its announce list. Rollback: switch Nginx back to php8.1-fpm.sock, systemctl start php8.1-fpm, and if needed apt install php8.1-fpm. Take a VM snapshot before the change. Test the app's critical paths during the window.