97

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?

muru
  • 197,895
  • 55
  • 485
  • 740
PHPLover
  • 1,787
  • 1
    How did you get PHP 5.5 on 12.04 in the first place? http://packages.ubuntu.com/precise-updates/php5 says it only has 5.3. – muru Dec 27 '14 at 04:55
  • @muru:That I don't know but currently I'm using PHP 5.5.19 is what the fact is. – PHPLover Dec 27 '14 at 05:56
  • 2
    Well, without knowing that, how can we know how to upgrade? And did you do sudo apt-get upgrade after the update? – muru Dec 27 '14 at 08:48

5 Answers5

107

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.

Eric Carvalho
  • 54,385
  • 4
    apt-get install php5 – Howard Jul 24 '15 at 08:20
  • To upgrade your 5.4 version of PHP, replace ondrej/php5 with ondrej/php5-oldstable. To upgrade your 5.6 version of PHP, replace ondrej/php5 with ondrej/php5-5.6. – rgajrawala Jul 26 '15 at 02:19
  • As rotaercz said, but was not very clear about it, you may also have to do an apt-get install php5 after Eric's original add/update/update sequence for php to actually upgrade to the latest version. Eric, you may want to edit your answer to include the last step. – Dale C. Anderson Aug 18 '15 at 21:48
  • After installing the php5-5.6 PPA, I ran sudo apt-get install php5 but my PHP version still says PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46) – BadHorsie Nov 23 '15 at 13:40
  • @BadHorsie We need more information. Please ask a new question and include the output of lsb_release -a and apt-cache policy php5. – Eric Carvalho Nov 23 '15 at 14:39
  • @EricCarvalho Thanks. http://askubuntu.com/questions/701547/cant-upgrade-to-php-5-6 – BadHorsie Nov 23 '15 at 15:21
  • I followed this for PHP5.5, and php -v gives me PHP 5.5.37-1+deb.sury.org~precise+2 (cli), but phpinfo() in apache gives me PHP Version 5.3.10-1ubuntu3.23 – cornernote Jun 29 '16 at 07:00
  • seems support for 12.04 has been removed - https://github.com/oerdnj/deb.sury.org/issues/248#issuecomment-181874972 – cornernote Jun 29 '16 at 07:23
  • I get sudo: apt-add-repository: command not found – Black Jul 26 '16 at 06:34
  • 1
    @EdwardBlack Try add-apt-repository. Or maybe you have to install the package software-properties-common. – Eric Carvalho Jul 26 '16 at 22:35
  • @EricCarvalho Does not work, I tried apt-get install software-properties-common but I get many lines with failed to get http://.... 404 Not found – Black Mar 06 '17 at 12:36
  • I was unable to retrieve these packages. It appears that they have stopped distribution of these packages for any Ubuntu version lower than 16.04, even though 14.04 is still maintained. – Coded Monkey Apr 03 '17 at 17:41
12

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
Kaviranga
  • 257
5

Run the following to add the PPA:

sudo apt-add-repository ppa:ondrej/php5

By upgrading PHP from version 5.3 to 5.5, this may upgrade your Apache from version 2.2 to 2.4. So be careful.

1

If you want to upgrade only PHP 5.3 to 5.5 and do not want to upgrade the system, then you need to install apache 2.4 as well.

sudo apt-add-repository ppa:ondrej/apache2 -y
sudo add-apt-repository ppa:ondrej/php -y
sudo aptitude update
sudo apt-get install apache2 libapache2-mod-php5 

Beware about some changes in apache 2.4 related to require grant all.

https://httpd.apache.org/docs/current/upgrading.html

Aruna
  • 119
  • 6
1

On Ubuntu 14

Only this line is needed

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

Then

sudo apt-get install php5

This will trigger the PPA upgrade system