124

PHP 7 came out yesterday and I would like to give it a try.

PHP 7.0.0 comes with a new version of the Zend Engine, numerous improvements and new features such as

  • Improved performance: PHP 7 is up to twice as fast as PHP 5.6
  • Significantly reduced memory usage
  • Abstract Syntax Tree
  • Consistent 64-bit support
  • Improved Exception hierarchy
  • Many fatal errors converted to Exceptions
  • Secure random number generator
  • Removed old and unsupported SAPIs and extensions
  • The null coalescing operator (??)
  • Return and Scalar Type Declarations
  • Anonymous Classes
  • Zero cost asserts

php.net


Is that possible to install it on current Ubuntu version?

Is there any current limitations or known compatibility issues?

hg8
  • 13,462

9 Answers9

187

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
  • 12
    Who is in charge of the ppa? Is it officially supported by zend? – k0pernikus Dec 04 '15 at 18:36
  • 1
    note that some extensions like memcache/memcached are still missing, more infos: https://www.dotdeb.org/2015/12/04/php-7-0-0-is-available-for-jessie/ – younes0 Dec 04 '15 at 21:56
  • 19
    @k0pernikus Zend does not officlally support anything beyond their Zend Server :-) Official Ubuntu packages are supported by Ubuntu's maintainers. This PPA is a personal effort by Ondřej Surý. Ondrey is the official owner of the PHP tree in Debian, which is upstream from Ubuntu. See here: https://qa.debian.org/developer.php?login=ondrej%40debian.org – Palantir Dec 05 '15 at 17:37
  • 4
    Anyway, his PHP PPAs are very popular, to the point where the official Magento distribution advertises the 5.5 and 5.6 version: http://devdocs.magento.com/guides/v2.0/install-gde/prereq/php-ubuntu.html – Palantir Dec 05 '15 at 17:38
  • I just installed PHP7 on my virtual machine via the PPA and it works well :D – Palantir Dec 05 '15 at 17:43
  • 3
    JFTR memcached isn't upstream ready for PHP 7.0 yet. I haven't looked at memcache, still ironing out smaller bugs after major rewrite of packaging scripts. – oerdnj Dec 09 '15 at 09:42
  • 1
    Script ran fine, but when I go to a page it outputs PHP rather than executing it. – Xeridea Dec 11 '15 at 21:52
  • 4
    @Xeridea Try sudo apt-get install libapache2-mod-php7.0, then sudo a2enmod php7.0 then restart Apache – andrewtweber Dec 13 '15 at 19:37
  • For Debian Jessie, I had to apt-get install software-properties-common before add-apt-repository ppa:ondrej/php-7.0 (add-apt-repository was not found) – The Onin Jan 15 '16 at 16:58
  • 1
    Sigh, @NinoŠkopac Don't use Ubuntu PPAs on Debian Jessie - rather go to https://packages.sury.org/php/ where are packages compiled for Debian Jessie. – oerdnj Jan 22 '16 at 12:50
  • 1
    Is purge rather than remove really necessary? If so, why? Users may want to look back at their PHP5 configuration and compare if things go wrong, but I believe purge would remove that. – tremby Mar 13 '16 at 02:37
  • libapache2-mod-php depends on libapache2-mod-php7.0; however: Package libapache2-mod-php7.0 is not configured yet.

    dpkg: error processing package libapache2-mod-php (--configure): dependency problems - leaving unconfigured No apport report written because the error message indicates its a followup error from a previous failure. Errors were encountered while processing: libapache2-mod-php7.0 libapache2-mod-php E: Sub-process /usr/bin/dpkg returned an error code (1)

    – kwoxer Jul 24 '16 at 19:18
  • Does not really work me. I'm not sure what my issue really is. – kwoxer Jul 24 '16 at 19:19
  • This definitely works but one issue I had was the php code would show up in the browser, php compile wouldn't load the app so using sudo apt-get install libapache2-mod-php7.0 fixed that issue – Rudy Jessop Dec 07 '16 at 04:33
22

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.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
thomasrutter
  • 36,774
18

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
HerrWalter
  • 103
  • 3
10

For Ubuntu 16.04, PHP7 is now the default official upstream version.

sudo apt install php

Here's a handy guide for setting up a LAMP stack on 16.04.

Jeff Puckett
  • 1,741
7

The above process did not work for my Ubuntu 15.10 server so I thought I would share what did work in case others find it helpful.

First I had to remove certain key PHP 5 modules:

sudo apt-get -y purge php5 libapache2-mod-php5 php5 php5-cli php5-common php5-curl php5-gd php5-imap php5-intl php5-json php5-mcrypt php5-mysql php5-pspell php5-readline php5-sqlite

Then remove a few extra things that were left behind:

sudo apt-get autoremove

Then install PHP 7.0:

sudo apt-get install php7.0

Then as PHPMyAdmin was removed Apache2 wouldn't start so I had to remove the config file (I could have moved it instead):

sudo rm /etc/apache2/conf-enabled/phpmyadmin.conf

Then I had to restart Apache2:

sudo service apache2 restart

PHP 7.0 was then running (confirmed with PHPINFO();)

However I have found the only way to get PHPMyAdmin working is to install/upgrade it manually as otherwise the latest version available in the sources doesn't support PHP 7 yet.

**EDIT: I have now found a way to get PHPMyAdmin updated to a compatible version without having to clone from GIT or compile manually from sources so I am adding this below:

First add this repository, update sources list and upgrade (NB: if it has been removed during the upgrade to PHP7 you will need to install rather than upgrade it):

sudo add-apt-repository ppa:nijel/phpmyadmin
sudo apt-get update
sudo apt-get dist-upgrade

However during installation (on my server) it had to run a database upgrade script upgrade_column_info_4_3_0+.sql but this failed with the following error:

mysql said: ERROR 1060 (42S21) at line 28: Duplicate column name 'input_transformation'

I chose to ignore the error and complete the upgrade. After installation I opened the .sql upgrade script at /usr/share/phpmyadmin/sql/upgrade_column_info_4_3_0+.sql

I ran the script manually removing the two offending lines trying to create 2 columns that already existed (code to remove):

ALTER TABLE `pma__column_info`
ADD `input_transformation` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
ADD `input_transformation_options` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '';

Finally I had to edit the config file at /etc/phpmyadmin/config.inc.php and add the following two lines:

$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

After this PHPMyAdmin is successfully updated and the extended features are enabled. Hope this helps others.

Robin Wilson
  • 211
  • 2
  • 8
4

At the time of this answer (February 2017), on Ubuntu 16.04 LTS, it is now possible to install php 7.0.* with the simple command:

apt-get install php

No need to add any third-party repositories.

3

I think the ppa has been added in 16.04 LTS.

  1. Just simply do sudo apt-get install php7.0 and that's it.
  2. Check if it installed by running php --version
  3. Also, you can create the info.php file in Apache's document root.
  4. That is in /var/www/html/ directory
  5. Run sudo gedit /var/www/html/info.php
  6. Add the following to the file: <?php phpinfo(); ?>. Note: the file is a blank file since you created it yourself.
  7. Now restart apache sudo service apache2 restart
  8. In your web browser, http://localhost/info.php that will give you full info about php.

Hope this helps :)

Collin
  • 581
2

I've collected a few different resources and resolved many issues to fully setup a build of PHP 7 on Ubuntu 15.04 and 15.10. Although it isn't a Debian package script, it does setup Ubuntu dependencies and configuration. The resources can be found over here.

You may need to select a release branch over just master and rerun the script.

m1st0
  • 109
2

I know that this may be a bad idea, but this is how I got php7 to work with my installation of Ubuntu Server 12.04.5 (i386):

sudo nano /etc/apt/sources.list

Then append the following at the end:
 

deb http://us.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://archive.canonical.com/ubuntu trusty partner

Then update as you normally would:

sudo apt-get update

Once you have PHP 7 installed on your apache server, you may have to move your files to a new directory to work:

sudo mv /var/www/* /var/www/html/