How to upgrade PHP version on Ubuntu
Assuming you installed PHP using the ppa:ondrej/php
PPA repository (see here for more info), your Ubuntu server is currently running an older version of PHP like 8.0.30
and you want to upgrade to a new version like 8.3.4
. Here’s one approach to doing that.
Upgrade package lists:
sudo apt-get update
Verify that the new PHP version is available for installing:
sudo apt-cache search php8.3
You should see a number of packages listed beginning with php8.3
(e.g., php8.3-zip
).
Make note of all the PHP 8.0.30 packages currently installed so that you can install all of these for the PHP 8.3.4 version too:
sudo apt list --installed | grep php8.0 | awk '{print $1}
This should output something like:
php8.0-cli/focal,now
php8.0-common/focal,now
php8.0-curl/focal,now
php8.0-fpm/focal,now
php8.0-imagick/focal,now
php8.0-mysql/focal,now
php8.0-opcache/focal,now
php8.0-readline/focal,now
php8.0-xml/focal,now
php8.0-zip/focal,now
Upgrade PHP to 8.3:
sudo apt-get install php8.3
Run the below command to check what PHP 8.3 packages have been installed:
sudo apt list --installed | grep php8.3 | awk '{print $1}'
Compare the output with what you got when you ran it for PHP 8.0 and then install any missing/required packages as needed. For example, if you had php8.0-zip
but you don’t have php8.3-zip
, then you might want to install php8.3-zip
to ensure all PHP extensions needed by your applications.are installed for the new version too.
Other potential changes
If you’re using PHP-FPM on a Unix socket with Nginx, you’ll want to update the relevant Nginx configuration to point to the correct socket.
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment