How to install PHP 7?
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?
Solution 1:
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
Solution 2:
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.
Solution 3:
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
Solution 4:
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.