How to Install PHP 7.0 on CentOS 7 / RHEL 7 Linux Systems

PHP7-CentOS7_logo

In this post, I’ll show you how to install php 7.0 on a bare CentOS7/RHEL7 Linux Systems. By default, CentOS 7 ships with PHP version 5.4 which has been officially reached it’s End of life for quite some time “in mid of 2015” and is no longer supported.

You can check the current support php versions on  php.net  website.

As we know that PHP is the most important part of LAMP applications (WordPress, Joomla, Drupal & Media wiki etc).

 

Now a days most of these applications require PHP 7 for their installation and configuration. Main advantage of PHP 7.x is that it will load your web application faster and will consume less server’s resources like CPU and RAM.

So, Let’s start

Prerequisites

All you need is a root access to the CentOS7/RHEL7 Servers, and no more

Step 1: Installing the required repositories and package

PHP 7.x packages are available in several different repositories. We’ll use the Remi repository which provides newer versions of various software packages including PHP.

The Remi repository depends on the EPEL repository, so we need to install the EPEL repository first. Also, we will need yum-utils package to enable the Remi repository “by default, it’s disabled at the installing time”.

Run the following commands to enable both EPEL and Remi repositories:

# yum -y install epel-release.noarch yum-utils

Run the following commands to enable Remi repositories:

# yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Step 2: Enable the required Remi repository

Let’s check on the available php version now, run this command:

# yum info php
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.prometeus.net
 * extras: mirrors.prometeus.net
 * updates: mirrors.prometeus.net
Available Packages
Name        : php
Arch        : x86_64
Version     : 5.4.16
Release     : 46.el7
Size        : 1.4 M
Repo        : base/7/x86_64
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP and Zend and BSD
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated web pages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            : 
            : The php package contains the module (often referred to as mod_php)
            : which adds support for the PHP language to Apache HTTP Server.

Why it’s still php 5.4.16?

This because we need to enable Remi-php70 repository, to configure PHP 7.0 repository, use below command:

# yum-config-manager --enable remi-php70

Now, we check again:

# yum info php
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.prometeus.net
 * epel: pkg.adfinis-sygroup.ch
 * extras: mirrors.prometeus.net
 * remi-php70: remi.mirror.wearetriple.com
 * remi-safe: remi.mirror.wearetriple.com
 * updates: mirrors.prometeus.net
remi-php70                                                                                                                                            | 3.0 kB  00:00:00     
remi-php70/primary_db                                                                                                                                 | 227 kB  00:00:04     
Available Packages
Name        : php
Arch        : x86_64
Version     : 7.0.33
Release     : 1.el7.remi
Size        : 2.6 M
Repo        : remi-php70
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP and Zend and BSD and MIT and ASL 1.0 and NCSA
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated web pages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            : 
            : The php package contains the module (often referred to as mod_php)
            : which adds support for the PHP language to Apache HTTP Server.

Now, the repository enabled.

Step 3: Install PHP 7.0

Run the following command to install PHP 7.0

# yum -y install php
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.prometeus.net
* epel: mirror.freethought-internet.co.uk
* extras: mirrors.prometeus.net
* remi-php70: mirror.reconn.ru
* remi-safe: mirror.reconn.ru
* updates: mirrors.prometeus.net
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:7.0.33-1.el7.remi will be installed
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: php-7.0.33-1.el7.remi.x86_64
--> Processing Dependency: php-cli(x86-64) = 7.0.33-1.el7.remi for package: php-7.0.33-1.el7.remi.x86_64
--> Processing Dependency: php-common(x86-64) = 7.0.33-1.el7.remi for package: php-7.0.33-1.el7.remi.x86_64
--> Processing Dependency: httpd for package: php-7.0.33-1.el7.remi.x86_64
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-88.el7.centos for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.centos.x86_64
---> Package php-cli.x86_64 0:7.0.33-1.el7.remi will be installed
--> Processing Dependency: libedit.so.0()(64bit) for package: php-cli-7.0.33-1.el7.remi.x86_64
---> Package php-common.x86_64 0:7.0.33-1.el7.remi will be installed
--> Processing Dependency: php-json(x86-64) = 7.0.33-1.el7.remi for package: php-common-7.0.33-1.el7.remi.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
---> Package httpd-tools.x86_64 0:2.4.6-88.el7.centos will be installed
---> Package libedit.x86_64 0:3.0-12.20121213cvs.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
---> Package php-json.x86_64 0:7.0.33-1.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================
Installing:
php x86_64 7.0.33-1.el7.remi remi-php70 2.6 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7_4.1 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
centos-logos noarch 70.0.6-3.el7.centos base 21 M
httpd x86_64 2.4.6-88.el7.centos base 2.7 M
httpd-tools x86_64 2.4.6-88.el7.centos base 90 k
libedit x86_64 3.0-12.20121213cvs.el7 base 92 k
mailcap noarch 2.1.41-2.el7 base 31 k
php-cli x86_64 7.0.33-1.el7.remi remi-php70 4.0 M
php-common x86_64 7.0.33-1.el7.remi remi-php70 1.0 M
php-json x86_64 7.0.33-1.el7.remi remi-php70 59 k

Transaction Summary
=============================================================================================================================================================================
Install 1 Package (+10 Dependent packages)

Total size: 32 M
Total download size: 32 M
Installed size: 60 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/remi-php70/packages/php-common-7.0.33-1.el7.remi.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEYB/s | 9.4 MB 00:00:15 ETA 
Public key for php-common-7.0.33-1.el7.remi.x86_64.rpm is not installed
(1/6): php-common-7.0.33-1.el7.remi.x86_64.rpm | 1.0 MB 00:00:08 
(2/6): php-json-7.0.33-1.el7.remi.x86_64.rpm | 59 kB 00:00:04 
(3/6): php-cli-7.0.33-1.el7.remi.x86_64.rpm | 4.0 MB 00:00:13 
(4/6): php-7.0.33-1.el7.remi.x86_64.rpm | 2.6 MB 00:00:18 
(5/6): httpd-2.4.6-88.el7.centos.x86_64.rpm | 2.7 MB 00:00:24 
(6/6): centos-logos-70.0.6-3.el7.centos.noarch.rpm | 21 MB 00:00:41 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 776 kB/s | 32 MB 00:00:41 
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
Userid : "Remi Collet <RPMS@FamilleCollet.com>"
Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
Package : remi-release-7.5-2.el7.remi.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : php-json-7.0.33-1.el7.remi.x86_64 1/11 
Installing : php-common-7.0.33-1.el7.remi.x86_64 2/11 
Installing : apr-1.4.8-3.el7_4.1.x86_64 3/11 
Installing : apr-util-1.5.2-6.el7.x86_64 4/11 
Installing : httpd-tools-2.4.6-88.el7.centos.x86_64 5/11 
Installing : centos-logos-70.0.6-3.el7.centos.noarch 6/11 
Installing : mailcap-2.1.41-2.el7.noarch 7/11 
Installing : httpd-2.4.6-88.el7.centos.x86_64 8/11 
Installing : libedit-3.0-12.20121213cvs.el7.x86_64 9/11 
Installing : php-cli-7.0.33-1.el7.remi.x86_64 10/11 
Installing : php-7.0.33-1.el7.remi.x86_64 11/11 
Verifying : libedit-3.0-12.20121213cvs.el7.x86_64 1/11 
Verifying : php-common-7.0.33-1.el7.remi.x86_64 2/11 
Verifying : php-7.0.33-1.el7.remi.x86_64 3/11 
Verifying : mailcap-2.1.41-2.el7.noarch 4/11 
Verifying : php-cli-7.0.33-1.el7.remi.x86_64 5/11 
Verifying : apr-util-1.5.2-6.el7.x86_64 6/11 
Verifying : php-json-7.0.33-1.el7.remi.x86_64 7/11 
Verifying : httpd-tools-2.4.6-88.el7.centos.x86_64 8/11 
Verifying : httpd-2.4.6-88.el7.centos.x86_64 9/11 
Verifying : apr-1.4.8-3.el7_4.1.x86_64 10/11 
Verifying : centos-logos-70.0.6-3.el7.centos.noarch 11/11

Installed:
php.x86_64 0:7.0.33-1.el7.remi

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 centos-logos.noarch 0:70.0.6-3.el7.centos httpd.x86_64 0:2.4.6-88.el7.centos 
httpd-tools.x86_64 0:2.4.6-88.el7.centos libedit.x86_64 0:3.0-12.20121213cvs.el7 mailcap.noarch 0:2.1.41-2.el7 php-cli.x86_64 0:7.0.33-1.el7.remi 
php-common.x86_64 0:7.0.33-1.el7.remi php-json.x86_64 0:7.0.33-1.el7.remi

Complete!


 

Step 4: Verify the PHP version

We can verify the PHP version either by command line or by a php test page.

  • Command Line Verification

Once all the PHP 7.0 and its dependencies are installed, use below command to verify the installed PHP version:

# php -v
PHP 7.0.33 (cli) (built: Dec  5 2018 14:22:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
  •  Test Page Verification

Apache web Server is installed on your system as a dependency for PHP, start its service using below systemctl command:

# systemctl start httpd

Now create a info.php file under /var/www/html, run the followingcommand to create the file’s contents

# echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Open the web browser and type the ip of your server followed by info.php,

php_version_7.0.33

This confirms that you have successfully installed PHP 7.0.33 on your system. That’s all from this article, please do share your feedback and comments.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

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