Article overview

Help article

I want to update the PHP version of Ubuntu / Debian

When using Ubuntu or Debian on your VPS this will usually come with a recent version of PHP (depending on the release you are using). Ubuntu 14.04 comes with PHP 5.5 and Ubuntu 16.04 with 7.0 by default. For Debian 7 the default PHP version is 5.4, Debian 8 uses 5.6.

Important!
- It is not without risk to update the PHP version on your VPS. You are advised to always create a snapshot before performing below commands in case something goes wrong.
- The current active version of PHP can be checked by the command php -v via the console (or SSH).
- The steps listed below have no mention of specific PHP 'handlers' or the configuration of your webserver. After updating PHP it is required to restart your webserver (Apache / Nginx) and change things in the configuration (especially when using Debian). To do so, consult the documentation as is supplied by the webserver software.

Adding an extra PHP repository
  • Because both Ubuntu and Debian by default do not have the latest version of PHP in their respective repositories, you will need to add an extra repository.
  • For Ubuntu:
    you can use the default repository from Ondrej for the latest version of PHP. To do so enter the following command:
    sudo add-apt-repository ppa:ondrej/php
  • Should you get an error (that the command is unknown), please enter the following:
    sudo apt-get update
    sudo apt-get install software-properties-common python-software-properties
    After this you can once again enter the 'add-apt-repository' command listed above.
  • For Debian:
    you can use the default repository from Dotdeb for the latest version of PHP. To do so enter the following command:
    sudo -s
    echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list
    echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list
  • After this you can install a newer version of PHP by using the following command (in the example 7.1):
    sudo apt-get install php7.1 php7.1-fpm
  • Please note! Above steps will most likely not work (anymore) in Debian 7. In that case you can consult the information listed here for an alternative solution.

Has this article been helpful?

Create an account or log in to leave a rating.

Comments

Create an account or log in to be able to leave a comment.