Install PHP 7.0 (7.0.1, 7.0.2, 7.0.3 & 7.0.4) on Linux

PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world. The PHP development team announces the immediate availability of PHP 7.0.0 on December 3, 2015 almost two years development journey, which is the next generation of the PHP programming language. It’s two times faster than PHP 5.6 and designed based on latest version of Zend Engine. The latest version of PHP 7.0.4 released on March 03, 2016 with bug fixes.

Upgrading PHP extensions from PHP5.x to 7.0 bit had because Many of the frequently used API functions have changed, such as the HashTable API. So, read carefully release notes and change log before proceeding upgrade or else you will fall in bad situation on production environment.

PHP 7 improvements and new features

  • 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 7 comes with a new version of the Zend Engine
  • compatibility with the latest OpenSSL 1.0.2e release
  • PHP 7 called as PHPNG (PHP Next Generation)

1) Remove PHP 5.x in Linux

Make sure, you should remove existing php5.x installation to avoid the conflict.

# For RHEL/CentOS #
# yum remove php* php-common

# For Ubuntu/Mint #
$ sudo apt-get remove php5*

2) Install PHP 7 in Ubuntu/Mint

We can easily install PHP7 on Ubuntu/Mint system using PPA.

# Adding PHP7 PPA #
$ sudo add-apt-repository ppa:ondrej/php-7.0

# Update repository list #
$ sudo apt-get update

# Install PHP7 #
$ sudo apt-get install -y php7.0

3) Install PHP 7 in Debian

We can easily install PHP7 on Debian system using Dotdeb.org Repo.

# Adding Dotdeb.org Repo #
$ sudo nano /etc/apt/sources.list
deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all

# Add Datdeb.org GPG key #
$ sudo wget https://www.dotdeb.org/dotdeb.gpg
$ sudo apt-key add dotdeb.gpg

# Update repository list #
$ sudo apt-get update

# Install PHP7 #
$ sudo apt-get install -y php7.0

4) Install PHP 7 in RHEL/CentOS

We can easily install PHP7 on RHEL/CentOS system via webtatic yum repository. webtatic Repository have some dependency with EPEL Repo, So we need to enable EPEL Repository too.

# For RHEL/CentOS 7 #
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

# For RHEL/CentOS 6 #
# rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

# Install PHP7 #
# yum install php70w

4a) Install PHP 7 in RHEL/CentOS/Fedora

Alternatively, We can easily install PHP7 on RHEL/CentOS/Fedora system via REMI Repository.

# yum --enablerepo=remi-php70 install php70

4b) Install PHP 7 openSUSE

We can install PHP7 on openSUSE by adding below repos.

# For openSUSE Leap 42.1 #
# zypper addrepo http://download.opensuse.org/repositories/devel:languages:php:php7/openSUSE_Leap_42.1/devel:languages:php:php7.repo
# zypper refresh
# zypper install apache-rpm-macros-control

# For openSUSE Leap 13.2 #
# zypper addrepo http://download.opensuse.org/repositories/devel:languages:php:php7/openSUSE_13.2/devel:languages:php:php7.repo
# zypper refresh
# zypper install apache-rpm-macros-control

5) Verify PHP Version

Simply fire the below command to verify the installed PHP version. The below output taken from CentOS 7.2.1511

# Output from RHEL/CentOS #
# php -v
PHP 7.0.0 (cli) (built: Dec  2 2015 20:42:32) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Screen shot taken from CentOS 7.2.1511.
install-php7-in-centos-rhel
Output taken from Ubuntu 15.10.

# Output from Ubuntu/Mint #
$ php -v
PHP 7.0.0-6+deb.sury.org~wily+1 (cli) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

Screen shot taken from Ubuntu 15.10.
install-php7-in-ubuntu

6) Install Necessary PHP Modules

Below list of modules are mandatory to run php website, so we can install in single shot.

# For RHEL/CentOS via webtatic #
# yum install php70w-xml php70w-soap php70w-xmlrpc php70w-mbstring php70w-json php70w-gd php70w-mcrypt

# For RHEL/CentOS/Fedora via REMI #
# yum --enablerepo=remi-php70 install php70w-xml php70w-soap php70w-xmlrpc php70w-mbstring php70w-json php70w-gd php70w-mcrypt

# For Ubuntu/Mint #
$ sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi

7) Listout PHP Modules

We can listout available PHP modules by searching it.

# For RHEL/CentOS via webtatic #
# yum search php70

# For RHEL/CentOS via REMI #
# yum --enablerepo=remi-php70 search php70

# For Ubuntu/Mint #
$ sudo apt-cache search php7-*

Plan and do upgrade to PHP7 to get faster delivery of your website. I have initiated for PHP7 migration, what about you guys.

3 Comments on “Install PHP 7.0 (7.0.1, 7.0.2, 7.0.3 & 7.0.4) on Linux”

  1. sudo add-apt-repository ppa:ondrej/php-7.0

    Cannot add PPA: ‘ppa:ondrej/php-7.0’.
    Please check that the PPA name or format is correct.

    1. Try this:

      sudo apt-get install -y language-pack-en-base
      sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

      Googled that problem kinda long, sadly dont remember where i got it, but works for me.

Leave a Reply

Your email address will not be published. Required fields are marked *