Ubuntu – How to upgrade PHP version to the latest stable released version

aptPHPupgrade

I'm using a system running on Ubuntu 12.04 LTS 64-bit OS.

I'm currently using following PHP version on this machine:

Command used to get the below info at terminal : php -v

Details I got are as below :

PHP 5.5.19-1+deb.sury.org~precise+1 (cli) (built: Nov 19 2014 19:32:34) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

Now I want to upgrade my PHP software to version 5.5.20.

Before asking the question I tried following command:

sudo apt-get update

Some information appeared. Then I again hit the following command:

php -v

but still the PHP software didn't update.

How should I do this?

Best Answer

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.