Upgrade to the specific php 7.1/7.2 from php 7.0 in Ubuntu 16.04

186,879

There is no official PHP 7.1 in the Ubuntu 16.04 repos.

If you want PHP 7.1, there is a version available in ppa:ondrej/php

You can install it like this:

  1. sudo add-apt-repository ppa:ondrej/php
  2. sudo apt-get update
  3. (optional) sudo apt-get remove php7.0
  4. sudo apt-get install php7.1 (from comments)

Remember that this is not an official upgrade path. The PPA is well known, and is relatively safe to use.

The PPA has co-installable packages (you can have multiple versions of PHP installed from that PPA). ~muru

Share:
186,879

Related videos on Youtube

Michele Carino
Author by

Michele Carino

Updated on September 18, 2022

Comments

  • Michele Carino
    Michele Carino almost 2 years

    How can I upgrade to php 7.1 from php 7.0 in ubuntu 16.04 ?

    If I do a php -v I get this message:

    PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
        with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies
    
    • The Onin
      The Onin over 7 years
      Why do you guys reckon Ubuntu isn't upgrading PHP to never minor versions? 7.0.8 has been superseded a few months ago.
    • Olavi Sau
      Olavi Sau over 6 years
      Because even minor PHP versions break compatibility. @see hash_function in php 7.1 vs php 7
  • Michele Carino
    Michele Carino over 7 years
    Thank yoy @ThatGuy, you are right, but I need conditional return types "?" and can't wait to use them :)
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    No problems. This should get you up and running :)
  • Michele Carino
    Michele Carino over 7 years
    I needed to launch also: 4. sudo apt-get install php7.1
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    Nice, updated the answer to add your step :)
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    May need to do it like this: sudo apt-get remove php7.0 and then sudo apt-get install php7.1. May have to test that further I think :)
  • muru
    muru over 7 years
    @ThatGuy The PPA has co-installable packages (you can have multiple versions of PHP installed from that PPA).
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    Thanks @muru That's actually really helpful! I've only ever installed one at a time. I think it may be my OCD kicking in ;) Added your note to the answer!
  • Michele Carino
    Michele Carino over 7 years
    @ThatGuy you can write your comment as answer, just adding the php7.0 removal (if needed) and that after that any extension should be reinstalled for php 7.1
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    @Pherserk - There you go, added as an optional step :)
  • The Onin
    The Onin over 7 years
    Worked for me as well on Ubuntu 16.04.01 LTS hosted on EC2.
  • redanimalwar
    redanimalwar over 7 years
    Why do 3. upgrade? If that ppa has a newer version for 7.0 it will be upgraded but what is the point when removing it seconds later? System upgrades are a nice thing to do but has are out of place when this is just about upgrading php
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    @redanimalwar - The PPA does not overwrite the stock PHP. Or at least didn't at the time of writing this answer.
  • redanimalwar
    redanimalwar over 7 years
    OK that makes my point even more valid.
  • AnotherKiwiGuy
    AnotherKiwiGuy over 7 years
    @redanimalwar - I'm definitely not opposed to keeping this answer up to date. Thanks for the edit :)
  • mos fetish
    mos fetish about 7 years
    So installing 7.1 from this ppa won't provide any automatic upgrade path? I'd need to install higher versions manually?
  • AnotherKiwiGuy
    AnotherKiwiGuy about 7 years
    Two questions. 1. Yes it will upgrade normally as long as you continue to use the PAPA. 2. You should be testing and installing the versions manually anyway, as part of a production server, but if you run apt-get upgrade, it will upgrade as a part of the routine.
  • Luke Cousins
    Luke Cousins almost 7 years
    If you got your PHP 7.0 from this PPA in the first place then to remove it, you need to run sudo apt-get remove php7.0*, not just sudo apt-get remove php7.0 as in point 3 above.
  • AnotherKiwiGuy
    AnotherKiwiGuy almost 7 years
    @LukeCousins - Yes, but that is not the correct answer based on the OP's question.
  • Victor Anuebunwa
    Victor Anuebunwa over 6 years
    This didn't work for me, i get E: Unable to locate package php7.1 E: Couldn't find any package by glob 'php7.1' E: Couldn't find any package by regex 'php7.1'
  • AnotherKiwiGuy
    AnotherKiwiGuy over 6 years
    @avonnadozie repeat step 1 and 2. It looks like the PPA has not been installed, or refreshed.
  • Raza
    Raza over 6 years
    Please follow this guide for more thorough guide: ayesh.me/Ubuntu-PHP-7.1
  • Damjan Pavlica
    Damjan Pavlica over 6 years
    Unable to locate package php7.1
  • AnotherKiwiGuy
    AnotherKiwiGuy over 6 years
    @DamjanPavlica - Then it sounds like the PPA didn't get added to the apt sources. You may have to run sudo add-apt-repository ppa:ondrej/php and sudo apt-get update again.
  • Damjan Pavlica
    Damjan Pavlica over 6 years
    @ThatGuy nope :(
  • AnotherKiwiGuy
    AnotherKiwiGuy over 6 years
    @DamjanPavlica - Ok, it's out of scope for this question. It's probably best to ask a new question and refer back to this one.
  • josircg
    josircg over 4 years
    Just to note: this repo updates also to php 7.2