How to install PHP 7?

You can do the following:

sudo apt-get install python-software-properties software-properties-common
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update

Optionally purge PHP 5:

sudo apt-get remove php5-common -y

Or directly purge it including configuration files:

sudo apt-get purge php5-common -y

And finally install PHP 7:

sudo apt-get install php7.0 php7.0-fpm php7.0-mysql -y

Optionally clean up unneeded packages afterwards:

sudo apt-get --purge autoremove -y

Alternatively, you can install PHP 7.0 from sources using this script script or following instruction on this blog.

EDIT:

PHP5 has now been replaced with PHP7 as the default PHP in Ubuntu 16.4 so, to install PHP7 on Ubuntu 16.04:

sudo apt-get install php7.0 

Or

sudo apt-get install php

You have two options:

  • Wait until there is a new Ubuntu release that includes PHP7

    Ubuntu won't release major new version releases to most software to existing Ubuntu versions; to get a major new version release you would need to wait until a newer version of Ubuntu.

  • Install a third-party version, such as from a PPA

    PPAs are not bound by the release schedules or policies of Ubuntu so they are free to change versions more frequently, among other things. The PPA mentioned in Tshilidzi Mudau's answer is a popular way of staying more up to date with PHP.

    sudo add-apt-repository ppa:ondrej/php
    

    PPAs don't come with the same official Ubuntu support as Ubuntu-supplied versions, and due to different schedules and policies may be of a different quality or security standard. In this case, the developer who makes this PPA available is well-known to the community here.


Here is my list of commands to fully update PHP with its dependencies, including phpMyAdmin (full LAMP stack):

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php-7.0
sudo apt-get update
sudo apt-get purge php5-fpm
sudo apt-get install php7.0-cli php7.0-common libapache2-mod-php7.0 php7.0 php7.0-mysql php7.0-fpm php7.0-curl php7.0-gd php7.0-bz2

Now you have PHP7. Let's go for phpMyAdmin: (start here if you have already PHP7 installed)

cd /var/www/html/
sudo wget https://files.phpmyadmin.net/phpMyAdmin/4.5.3.1/phpMyAdmin-4.5.3.1-all-languages.zip
sudo unzip phpMyAdmin-4.5.3.1-all-languages.zip
sudo mv phpMyAdmin-4.5.3.1-all-languages/ phpmyadmin/
sudo mkdir -m 777 phpmyadmin/config/
sudo /etc/init.d/apache2 restart

Tags:

Php

Php7