Install PHP 7/7.1 in CentOS from third party repository


PHP is one of the must have application for any modern web server. Despite being one of the most popular web server OS, CentOS’s official repository  at the moment comes with php version 5.4. Version 5.4 is pretty old version. Many modern web application needs the enhanced capability of newer versions og php.( For example, popular ecommerce cms “Magento” needs PHP 7 or higher.)

 

[root@localhost ~]# yum info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.netsite.dk
 * extras: mirror.netsite.dk
 * updates: mirror.netsite.dk
Available Packages

Name        : php
Arch        : x86_64
Version     : 5.4.16
Release     : 42.el7
Size        : 1.4 M
Repo        : base/7/x86_64
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
Licence     : 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.

So it is not possible to upgrade to higher version like PHP 7 on centos using the usual way. we need to use third party repositories like remi , ius or webtatic.

Using Remi for :

First we will install epel(extra packages for enterprise linux) repository.

yum -y install epel-release

Next we will install the remi repository in our system.

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

Now we will install yum config tool, which actually increases the functionality of yum. This tools helps us to easily enable/disable repositories in centos.

yum -y install yum-utils

Now enable the remi repo with the following command.( use php70 or php72 if you need php version 7.0 or 7.2 respectively)

yum-config-manager --enable remi-php71

Now the actual installation. We will instal php and some commonly used php modules on the system.

yum -y install php php-mcrypt php-cli php-gd php-curl php-mysql php-mbstring

Now check the php version in the system.

[root@localhost ~]# php -v
PHP 7.1.11 (cli) (built: Oct 25 2017 10:24:28) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

Using Webtatic:

As usual install the epel repo first.

 yum -y install epel-release

Then install webtatic repo .

yum -y install https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Then we install php and other necessary module:

yum install -y mod_php71w php71w-cli php71w-common php71w-gd php71w-mbstring php71w-mcrypt php71w-mysqlnd

Then check the version:

[root@localhost ~]# php -v
PHP 7.1.10 (cli) (built: Sep 30 2017 10:30:04) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

Using IUS:


Install the epel repo and IUS repo with the following commands.

yum -y install epel-release
yum install https://centos7.iuscommunity.org/ius-release.rpm

Next install the necessary php module. Here 71u means the 7.1 version and the ‘u’ denotes that it is from ius. Use 70 or 72 if you want 7.0 or 7.2 version.

yum install -y mod_php71u php71u-cli php71u-common php71u-gd php71u-mbstring php71u-mcrypt php71u-mysqlnd

As a sidenote , PHP 7 from official centos repo will not probably be available until release of RHEL 8.

Leave a comment

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