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:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
- (optional)
sudo apt-get remove php7.0
-
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
Related videos on Youtube
![Michele Carino](https://i.stack.imgur.com/xlPLG.jpg?s=256&g=1)
Author by
Michele Carino
Updated on September 18, 2022Comments
-
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 over 7 yearsWhy 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 over 6 yearsBecause even minor PHP versions break compatibility. @see hash_function in php 7.1 vs php 7
-
-
Michele Carino over 7 yearsThank yoy @ThatGuy, you are right, but I need conditional return types "?" and can't wait to use them :)
-
AnotherKiwiGuy over 7 yearsNo problems. This should get you up and running :)
-
Michele Carino over 7 yearsI needed to launch also: 4. sudo apt-get install php7.1
-
AnotherKiwiGuy over 7 yearsNice, updated the answer to add your step :)
-
AnotherKiwiGuy over 7 yearsMay need to do it like this:
sudo apt-get remove php7.0
and thensudo apt-get install php7.1
. May have to test that further I think :) -
muru over 7 years@ThatGuy The PPA has co-installable packages (you can have multiple versions of PHP installed from that PPA).
-
AnotherKiwiGuy over 7 yearsThanks @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 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 over 7 years@Pherserk - There you go, added as an optional step :)
-
The Onin over 7 yearsWorked for me as well on Ubuntu 16.04.01 LTS hosted on EC2.
-
redanimalwar over 7 yearsWhy 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 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 over 7 yearsOK that makes my point even more valid.
-
AnotherKiwiGuy over 7 years@redanimalwar - I'm definitely not opposed to keeping this answer up to date. Thanks for the edit :)
-
mos fetish about 7 yearsSo installing 7.1 from this ppa won't provide any automatic upgrade path? I'd need to install higher versions manually?
-
AnotherKiwiGuy about 7 yearsTwo 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 almost 7 yearsIf 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 justsudo apt-get remove php7.0
as in point 3 above. -
AnotherKiwiGuy almost 7 years@LukeCousins - Yes, but that is not the correct answer based on the OP's question.
-
Victor Anuebunwa over 6 yearsThis 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 over 6 years@avonnadozie repeat step 1 and 2. It looks like the PPA has not been installed, or refreshed.
-
Raza over 6 yearsPlease follow this guide for more thorough guide: ayesh.me/Ubuntu-PHP-7.1
-
Damjan Pavlica over 6 yearsUnable to locate package php7.1
-
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
andsudo apt-get update
again. -
Damjan Pavlica over 6 years@ThatGuy nope :(
-
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 over 4 yearsJust to note: this repo updates also to php 7.2