68

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
2
  • Why do you guys reckon Ubuntu isn't upgrading PHP to never minor versions? 7.0.8 has been superseded a few months ago.
    – The Onin
    Dec 15, 2016 at 2:10
  • 1
    Because even minor PHP versions break compatibility. @see hash_function in php 7.1 vs php 7
    – Olavi Sau
    Nov 27, 2017 at 11:30

1 Answer 1

138

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

26
  • 2
    Thank yoy @ThatGuy, you are right, but I need conditional return types "?" and can't wait to use them :) Dec 4, 2016 at 8:40
  • 1
    I needed to launch also: 4. sudo apt-get install php7.1 Dec 4, 2016 at 8:42
  • 2
    @ThatGuy The PPA has co-installable packages (you can have multiple versions of PHP installed from that PPA).
    – muru
    Dec 4, 2016 at 8:46
  • 1
    @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 Dec 4, 2016 at 9:59
  • 3
    Just to note: this repo updates also to php 7.2
    – josircg
    Oct 28, 2019 at 15:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.