apt-get update updates only the package lists. To actually upgrade the packages you have to run:

sudo apt-get upgrade

or

sudo apt-get dist-upgrade

More info here.


If you ran the above commands but the packages still were not upgraded, probably you didn't add Ondřej Surý's PHP PPA to your system.

Run the following to add the PPA:

  • For PHP 5.5, PHP 5.6 and PHP 7.0:

    sudo apt-add-repository ppa:ondrej/php
    
  • For PHP 5.4 (Deprecated, upgrade at least to PHP 5.5):

    sudo apt-add-repository ppa:ondrej/php5-oldstable
    
  • For PHP 5.5 (Deprecated, use ppa:ondrej/php):

    sudo apt-add-repository ppa:ondrej/php5
    
  • For PHP 5.6 (Deprecated, use ppa:ondrej/php):

    sudo apt-add-repository ppa:ondrej/php5-5.6
    

Then update the package lists and perform the upgrade:

sudo apt-get update

For PHP 5.5:

sudo apt-get install php5.5

For PHP 5.6:

sudo apt-get install php5.6

For PHP 7:

sudo apt-get install php7.0

Release upgrade

If you want to install the latest PHP (for example PHP7) but you want to stick to the release's packages intead of hacking the sources around; and you want to do a full-release upgrade (for example you are in Ubuntu 14.04 -which does not have php7- and you want to go to Ubuntu 16.04 -which does- then you can do:

do-release-upgrade

Now you should have the latest PHP version.

Answer from Eric Carvalho on askubuntu.com
Top answer
1 of 5
108

apt-get update updates only the package lists. To actually upgrade the packages you have to run:

sudo apt-get upgrade

or

sudo apt-get dist-upgrade

More info here.


If you ran the above commands but the packages still were not upgraded, probably you didn't add Ondřej Surý's PHP PPA to your system.

Run the following to add the PPA:

  • For PHP 5.5, PHP 5.6 and PHP 7.0:

    sudo apt-add-repository ppa:ondrej/php
    
  • For PHP 5.4 (Deprecated, upgrade at least to PHP 5.5):

    sudo apt-add-repository ppa:ondrej/php5-oldstable
    
  • For PHP 5.5 (Deprecated, use ppa:ondrej/php):

    sudo apt-add-repository ppa:ondrej/php5
    
  • For PHP 5.6 (Deprecated, use ppa:ondrej/php):

    sudo apt-add-repository ppa:ondrej/php5-5.6
    

Then update the package lists and perform the upgrade:

sudo apt-get update

For PHP 5.5:

sudo apt-get install php5.5

For PHP 5.6:

sudo apt-get install php5.6

For PHP 7:

sudo apt-get install php7.0

Release upgrade

If you want to install the latest PHP (for example PHP7) but you want to stick to the release's packages intead of hacking the sources around; and you want to do a full-release upgrade (for example you are in Ubuntu 14.04 -which does not have php7- and you want to go to Ubuntu 16.04 -which does- then you can do:

do-release-upgrade

Now you should have the latest PHP version.

2 of 5
13

For newest updating process use the following command

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

Then run the following command in terminal

sudo apt-get update 

This is worked well when installing php 5.5,5.6 and 7.0

If there some errors this command will resolve the errors

sudo dpkg --configure -a

Update 2020-10-14: For versions upto 7.*

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

Then

sudo apt install php7.2

Here also you can use this for php 7.0,7.1,7.3 to 7.4

After updating process you can use below command to install extensions

sudo apt update 
sudo apt install php-xml

or you can use like below

sudo apt install php7.2 php-xml  

Update 2021-01-31: For versions upto 8.*

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

Then

sudo apt install -y php8.0 php8.0-cli php8.0-common
🌐
DEV Community
dev.to › xxzeroxx › how-to-update-php-in-linux-to-any-version-16mp
How to Update PHP in Linux to any version - DEV Community
January 13, 2024 - Replace Z.W with the version you want to enable (e.g., php8.2). ... Edit the Nginx configuration file (commonly /etc/nginx/sites-available/default) and update the fastcgi_pass directive to point to the new PHP-FPM version socket.
🌐
Reddit
reddit.com › r/linuxquestions › is it difficult/risky to update php version?
r/linuxquestions on Reddit: Is it difficult/risky to update php version?
November 30, 2023 -

I run my own site on a linux server (Ubuntu 18.04) on a dedicated server, my knowledge on linux and programming is pretty low, i managed to install the site and all a couple of years ago but now i need to update it to a newer version that requires php 8.2 and i currently have php 7.2.

My question is, is it hard to change versions and how risky it is to do so, since i don't know much i'm afraid to loose dbs or my website (I wil have backups just in case).

Thanks in advance.

🌐
Allotmentandy
allotmentandy.github.io › blog › 2023-01-16-Upgrading-PHP-to-version-8-2-on-Debian-Linux
Upgrading PHP to version 8.2 on Debian Linux | Allotment Andy
sudo apt install php8.2-cli php8.2-curl ... libapache2-mod-php8.2 php8.2-fpm -y · To activate the new version (or select an older version) the command 'update-alternatives' can be used thus:...
🌐
Webdock.io
webdock.io › docs › perfect server stacks › upgrade or downgrade php › upgrading or downgrading php versions
Upgrade or Downgrade PHP • Switch Versions »
December 4, 2025 - Switch PHP versions easily. Step-by-step guide to installing specific PHP versions and updating Nginx/Apache configuration to match »
🌐
TehnoBlog.org
tehnoblog.org › ubuntu-tutorial-how-to-manually-upgrade-php-version
Ubuntu 16.04 Tutorial – How To Manually Upgrade PHP Version - TehnoBlog.org
If you use cPanel, DirectAdmin, Plesk, Webmin… or Shared / Managed / CloudLinux hosting, you can simply change PHP version directly from the control panel itself (here’s an example for cPanel, of course, don’t forget to tick all required checkboxes for PHP extensions which your application requires to properly run!). Contact your hosting support for more details. In this brief article we will show you how to manually install and update PHP version to the latest 7.x or 8.x version on Ubuntu LTS VPS server using apt package manager.
🌐
DedicatedCore
dedicatedcore.com › home › how to upgrade php on ubuntu 20.04 | 22.04
How to Upgrade PHP on Ubuntu 20.04 | 22.04 - DedicatedCore Blog
May 20, 2025 - You must add the PHP repository to your system to upgrade to PHP 8.2. To add the repository, type the following instructions into the console. sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update
Find elsewhere
🌐
TurnKey GNU/Linux
turnkeylinux.org › forum › support › sun-20220102-1231 › upgrading-php73-74-or-8
Upgrading PHP7.3 to 7.4 or 8 | TurnKey GNU/Linux
... [NOTE: the following will not work for some reason on Webmin for me] ======================= on the WordPress Appliance Services Window: Click Enter to Quit Login as root ... apt update apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 echo ...
🌐
Medium
roman-academy.medium.com › how-to-update-php-version-in-ubuntu-linux-6d3934844938
How to update PHP version in Ubuntu Linux | by RomanAcademy | Medium
November 6, 2022 - To install PPA easily, you need ... the PPA sudo add-apt-repository ppa:ondrej/php# 👇 refresh the package manager sudo apt-get update# 👇 install latest PHP version sudo apt -y install php8.1...
🌐
Ubuntu Community Hub
discourse.ubuntu.com › support and help
Upgrading PHP version - Support and Help - Ubuntu Community Hub
June 6, 2025 - I need to update my php version for an app. Here is the version I am running: PHP 8.1.2-1ubuntu2.21 (cli) (built: Mar 24 2025 19:04:23) (NTS). I am running Ubuntu 22.04.5. My system says it is up-to-date. How do I ge…
🌐
PHP.Watch
php.watch › articles › php-84-install-upgrade-guide-debian-ubuntu
PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian • PHP.Watch
November 21, 2024 - A guide for Debian and Ubuntu on how to install PHP 8.4 on a new server or how to upgrade an existing PHP setup to PHP 8.4.
🌐
Vultr
docs.vultr.com › how-to-upgrade-php-8-2-to-8-3-on-ubuntu
How to Upgrade PHP 8.2 to 8.3 on Ubuntu Complete Guide | Vultr Docs
April 23, 2025 - You will update the PHP repository sources, install PHP 8.3, install PHP-FPM and common PHP extenstions to use PHP with the Apache or Nginx web server. ... Have access to an Ubuntu 24.04 instance with PHP 8.2 already installed. Log in to the instance as a non-root user with sudo privileges to install new packages. The default APT package repository sources include limited PHP versions on Ubuntu 24.04.
🌐
Linode
linode.com › docs › guides › how-to-update-php-for-wordpress
How to Update PHP for WordPress on Ubuntu 20.04 | Linode Docs
August 6, 2021 - If you are not familiar with the sudo command, see the Linux Users and Groups guide. PHP usually has to be upgraded in one of two situations; when WordPress is first installed, or when it is upgraded to a newer version.
🌐
PHP.Watch
php.watch › articles › php-8.3-install-upgrade-on-debian-ubuntu
How to install or upgrade to PHP 8.3 on Ubuntu and Debian • PHP.Watch
November 12, 2023 - A complete guide to install or upgrade to PHP 8.3 on Ubuntu 22.04 (Jammy), Ubuntu 20.04 (Focal), Debian 10 (Buster), 11 (Bullseye), and Debian 12 (Bookworm).
🌐
Zomro
zomro.com › blog › faq › 436-updatingdowngrading-php-versions-on-ubuntu
Updating/Downgrading PHP Versions on Ubuntu | Zomro
December 7, 2023 - In this article, we will be updating and downgrading PHP versions on Ubuntu 20.04.
🌐
Liquid Web
liquidweb.com › home › help docs › server administration › linux server administration › upgrading or installing php on ubuntu 22.04
Upgrading or Installing PHP on Ubuntu — PHP 8.2 and Ubuntu 22.04 | Liquid Web
December 15, 2025 - While Ubuntu 22.04 does not include the latest PHP versions by default, we are adding the official repository maintained by Ondřej Surý on Launchpad. Add the PHP repository. Run the following commands, pressing ‘Enter‘ when prompted to confirm adding the repository: apt-get install python-software-propertiessudo add-apt-repository ppa:ondrej/php · Update your system’s package list.