Ubuntu 22.04.3 LTS is Ready for PHP 8.3, WordPress 6.4.* is Not — How to Proceed?

I generally upgrade my servers with the following command:

sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'

Is there a clean way to upgrade everything except for PHP, or would it be easier just to upgrade everything and then rollback to PHP 8.2? I learned the hard way with a recent upgrade that WordPress isn’t ready for PHP 8.3 (https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/), and had to do a complete fresh install of PHP:

sudo add-apt-repository --remove ppa:ondrej/php

sudo apt purge php*
sudo apt autoremove
sudo rm -rf /etc/php/8.3
sudo rm -rf /usr/lib/php

sudo apt install php php-mysql
sudo service apache2 restart

Note: Ubuntu moved to PHP 8.3 on January 18th: https://discourse.ubuntu.com/t/noble-numbat-release-schedule/35649

Asked By: ABuntToo

||

You need to use apt-mark hold to pin the php version before you do your upgrade. The php 8.3 version that meets your requirements is 2:8.3+94+ubuntu22.04.1+deb.sury.org+2. The modified list of steps you want to do is the following:

# Your original cleaning up of the wrong version
sudo add-apt-repository --remove ppa:ondrej/php
sudo apt purge php*
sudo apt autoremove
sudo rm -rf /etc/php/8.3
sudo rm -rf /usr/lib/php

# I do not recommend removing ppa:ondrej/php .
# Ubuntu 22.04 has php 8.1, and you need the ppa for php 8.3
sudo add-apt-repository ppa:ondrej/php # Readd

# Install and pin the correct version
sudo apt install php=2:8.3+94+ubuntu22.04.1+deb.sury.org+2 php-mysql
sudo apt-mark php # Prevent apt-get {,dist-}upgrade from changing the version.
sudo service apache2 restart

# Later, routine upgrades will not touch the php version
# They will show it below the "The following packages have been kept back:" line
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get autoremove -y
apt-get autoclean -y

Take care to avoid running these steps in the wrong order. It is counterproductive to run upgrades and dist-upgrades before running apt-mark. That would just pin the latest version available at the time of that command, not version 8.3 like you want. You need to run apt-mark either immediately after apt-get install php=<the version you want> or after verifying the installed version is already the version you want.

This will hold back the package at the exact major.minor.patch version, including the patch version, not just major or minor.

Answered By: Daniel T
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.