How update from PHP 7.x to PHP 8.x at Ubuntu Linux

·

Apt compatibility

Another point to consider is that often an older PHP version, such as 7.4, is running on an older Ubuntu Linux distribution like 20.04. In this case, updates via apt to newer packages like those for PHP 8 will also be problematic. If possible, first update your Linux distribution to the latest LTS version.

Code compatibility

Upgrading from any version of PHP 7 to any version of PHP 8 is a major version jump and there is no single “self-update” command or “auto-update” button to do this, furthermore PHP 8 introduces breaking changes that could stop your old code from working, so we need be careful with this update.

However, assuming all the risks of the code, we will perform the update using the apt package manager. Below let’s see the process to upgrade your system.

The “Ondřej Surý” PPA

Standard Ubuntu repositories usually lack the newest PHP versions, so you need use the standard third-party repository maintained by Ondřej Surý (a Debian PHP maintainer). To do it, type in shell:

sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Get he extensions you had for PHP 7.x

dpkg -l | grep php7 | cut -d ' ' -f 3
Output:

$ dpkg -l | grep php7 | cut -d ' ' -f 3
php7.4-cli
php7.4-common
php7.4-mbstring
php7.4-opcache
php7.4-readline
php7.4-xml

Install PHP 8.x

In a text editor, you can paste the output of the grep, and create your install command replacing what you need, like this:

sudo apt install -y php8.4 php8.4-cli php8.4-common php8.4-mbstring php8.4-opcache php8.4-readline php8.4-xml

Okay, now you have PHP 8 configured with the same packages as PHP 7.


Create your own user feedback survey

Comments

One response to “How update from PHP 7.x to PHP 8.x at Ubuntu Linux”

  1. […] You can find a tutorial on how to update your PHP 7 to PHP 8 here. […]

Leave a Reply

Your email address will not be published. Required fields are marked *