One of the challenges Linux users face is upgrading PHP to newer versions.
Even with older versions such as version 26 and earlier registering and configuring PHP repositories (mirrors) can sometimes prove difficult.
For this reason, in this post, we will explore how to upgrade PHP to newer versions on Linux and provide solutions for potential issues that may arise.
1. First, retrieve the repository's signing key from the Ubuntu Keyserver and verify it:
2. Add the repository for Ubuntu 24.04:
3. Update the package list and check access:
4. If Candidate shows a version of PHP 8.5, install it:
5. Final Review:
6. If you want PHP 8.5 to be the default version
If the PHP 8.5 option appears, select the corresponding number.
Good luck.
bash
sudo apt install -y curl ca-certificates gnupgbash
sudo mkdir -p /etc/apt/keyringsbash
curl -fsSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xB8DC7E53946656EFBCE4C1DD71DAEAAB4AD4CAB6' \ | gpg --dearmor \ | sudo tee /etc/apt/keyrings/ondrej-php.gpg >/dev/null
bash
echo "deb [signed-by=/etc/apt/keyrings/ondrej-php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble main" \ | sudo tee /etc/apt/sources.list.d/ondrej-php.list
bash
sudo apt update
apt-cache policy php8.5-commonbash
sudo apt install -y php8.5-cli php8.5-common php8.5-bcmath php8.5-bz2 php8.5-curl php8.5-gd php8.5-gmp php8.5-intl php8.5-mbstring php8.5-readline php8.5-xml php8.5-zip
bash
php8.5 -v php8.5 -m
bash
sudo update-alternatives --config phpcommit 58d4df7