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

PHP7-CentOS7_logo

In this post, I’ll show you how to install php 7.1 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-php71 repository, to configure PHP 7.1 repository, use below command:

# yum-config-manager --enable remi-php71

Now, we check again:

# yum info php
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.prometeus.net
 * epel: ftp.arnes.si
 * extras: mirrors.prometeus.net
 * remi-php70: ftp.arnes.si
 * remi-php71: ftp.arnes.si
 * remi-safe: ftp.arnes.si
 * updates: mirrors.prometeus.net
remi-php71                                                                                                                                            | 3.0 kB  00:00:00     
remi-php71/primary_db                                                                                                                                 | 233 kB  00:00:02     
Available Packages
Name        : php
Arch        : x86_64
Version     : 7.1.25
Release     : 2.el7.remi
Size        : 3.0 M
Repo        : remi-php71
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.1

Run the following command to install PHP 7.1

# yum -y install php
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.prometeus.net
* epel: mirror.de.leaseweb.net
* extras: mirrors.prometeus.net
* remi-php70: remi.mirror.karneval.cz
* remi-php71: remi.mirror.karneval.cz
* remi-safe: remi.mirror.karneval.cz
* updates: mirrors.prometeus.net
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:7.1.25-2.el7.remi will be installed
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: php-7.1.25-2.el7.remi.x86_64
--> Processing Dependency: php-cli(x86-64) = 7.1.25-2.el7.remi for package: php-7.1.25-2.el7.remi.x86_64
--> Processing Dependency: php-common(x86-64) = 7.1.25-2.el7.remi for package: php-7.1.25-2.el7.remi.x86_64
--> Processing Dependency: httpd for package: php-7.1.25-2.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.1.25-2.el7.remi will be installed
--> Processing Dependency: libedit.so.0()(64bit) for package: php-cli-7.1.25-2.el7.remi.x86_64
---> Package php-common.x86_64 0:7.1.25-2.el7.remi will be installed
--> Processing Dependency: php-json(x86-64) = 7.1.25-2.el7.remi for package: php-common-7.1.25-2.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.1.25-2.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================
Installing:
php x86_64 7.1.25-2.el7.remi remi-php71 3.0 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.1.25-2.el7.remi remi-php71 4.6 M
php-common x86_64 7.1.25-2.el7.remi remi-php71 1.0 M
php-json x86_64 7.1.25-2.el7.remi remi-php71 61 k

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

Total download size: 33 M
Installed size: 63 M
Downloading packages:
(1/11): apr-1.4.8-3.el7_4.1.x86_64.rpm | 103 kB 00:00:01 
(2/11): libedit-3.0-12.20121213cvs.el7.x86_64.rpm | 92 kB 00:00:01 
(3/11): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00 
(4/11): httpd-tools-2.4.6-88.el7.centos.x86_64.rpm | 90 kB 00:00:04 
(5/11): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:15 
(6/11): php-common-7.1.25-2.el7.remi.x86_64.rpm | 1.0 MB 00:00:15 
(7/11): php-json-7.1.25-2.el7.remi.x86_64.rpm | 61 kB 00:00:07 
(8/11): httpd-2.4.6-88.el7.centos.x86_64.rpm | 2.7 MB 00:00:40 
(9/11): php-7.1.25-2.el7.remi.x86_64.rpm | 3.0 MB 00:00:41 
(10/11): php-cli-7.1.25-2.el7.remi.x86_64.rpm | 4.6 MB 00:00:59 
(11/11): centos-logos-70.0.6-3.el7.centos.noarch.rpm | 21 MB 00:01:56 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 290 kB/s | 33 MB 00:01:56 
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7_4.1.x86_64 1/11 
Installing : apr-util-1.5.2-6.el7.x86_64 2/11 
Installing : httpd-tools-2.4.6-88.el7.centos.x86_64 3/11 
Installing : php-common-7.1.25-2.el7.remi.x86_64 4/11 
Installing : php-json-7.1.25-2.el7.remi.x86_64 5/11 
Installing : centos-logos-70.0.6-3.el7.centos.noarch 6/11 
Installing : libedit-3.0-12.20121213cvs.el7.x86_64 7/11 
Installing : php-cli-7.1.25-2.el7.remi.x86_64 8/11 
Installing : mailcap-2.1.41-2.el7.noarch 9/11 
Installing : httpd-2.4.6-88.el7.centos.x86_64 10/11 
Installing : php-7.1.25-2.el7.remi.x86_64 11/11 
Verifying : php-7.1.25-2.el7.remi.x86_64 1/11 
Verifying : php-json-7.1.25-2.el7.remi.x86_64 2/11 
Verifying : mailcap-2.1.41-2.el7.noarch 3/11 
Verifying : libedit-3.0-12.20121213cvs.el7.x86_64 4/11 
Verifying : php-common-7.1.25-2.el7.remi.x86_64 5/11 
Verifying : apr-util-1.5.2-6.el7.x86_64 6/11 
Verifying : httpd-tools-2.4.6-88.el7.centos.x86_64 7/11 
Verifying : httpd-2.4.6-88.el7.centos.x86_64 8/11 
Verifying : php-cli-7.1.25-2.el7.remi.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.1.25-2.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.1.25-2.el7.remi 
php-common.x86_64 0:7.1.25-2.el7.remi php-json.x86_64 0:7.1.25-2.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.1 and its dependencies are installed, use below command to verify the installed PHP version:

# php -v
PHP 7.1.25 (cli) (built: Dec  8 2018 13:52:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologie
  •  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 following command 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.1.25

This confirms that you have successfully installed PHP 7.1.25 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 *