Miscellaneouss

How To Install PHP 7 On RHEL/CentOS/Fedora/Ubuntu And Debian System

PHP is the scripting language which is used to generate dynamic web page. It contain TEXT,HTML and SCRIPT BLOCKS. Whenever user request for a PHP page through web browser than PHP script execute on web server and display the requested result in browser.

PHP 7.1 is the latest stable release version of PHP. It was released on December  3, 2015. It provides 2x faster performance and 50% better memory consumption than PHP version 5.6. To install PHP version 7 you will need to install a PPA called ondrej/php. This allows you to co-install PHP 5.6 version and PHP 7.0 version. If you want to install PHP 7 on your system this article will helpful for you. In this article I am going to explain how we can install PHP 7.1 stable version on RHEL/CentOS/Fedora/Ubuntu and Debian System.

INSTALL PHP 7.1 ON UBUNTU

Follow the below command to install PHP 7 on Ubuntu and Debian system. First you will need to install PPA for PHP 7.

Adding PPA Repository For PHP 7

PPA ( Personal Package Archive) is an apt repository hosted on Launchpad. It allow third-party developers to build and distribute packages for Ubuntu and Debian system outside of the official channels. Follow the below steps to install PPA repository.

# sudo apt-get install python-software-properties
# sudo add-apt-repository ppa:ondrej/php
# sudo apt-get update
# sudo apt-get install php7.1 -y

Now Follow the below command to verify the installed php version on your Linux system.

# php -v

PHP 7.1.0-5+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies.
with Zend OPcache v7.1.0-5+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies.

INSTALL PHP 7.1 ON FEDORA

Follow the below command to install PHP 7.1 on Fedora. First you will need to install remi repository on system.

Remi Repository Installation:

On Fedora 23

# rpm -Uvh http://rpms.famillecollet.com/fedora/remi-release-23.rpm

On Fedora 24

# rpm -Uvh http://rpms.famillecollet.com/fedora/remi-release-24.rpm

On Fedora 25

# rpm -Uvh http://rpms.famillecollet.com/fedora/remi-release-25.rpm

PHP 7.1 Installation on Fedora:

# dnf --enablerepo=remi --enablerepo=remi-php71 install php php-common

INSTALL PHP 7.1 ON CENTOS/RHEL

Follow the below command to install PHP 7.1 on RHEL and CentOS system.

Remi Repository Installation:

On CentOS 6

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

On CentOS 7

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

PHP 7.1 Installation on RHEL and CentOS:

# yum --enablerepo=remi,remi-php71 install php php-common

INSTALL PHP 7.1 MODULES

After installing PHP 7.1 on system you may also install PHP modules as per your application requirements.

Follow the below command to install PHP Modules.

On Ubuntu and Debian

# apt-get install php7.1-mysql php7.1-curl php7.1-json php7.1-cgi php7.1-xml php7.1-xmlrpc php7.1-zip php7.1-opcache php7.1-xsl

On Fedora

# dnf --enablerepo=remi --enablerepo=remi-php71 install php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

On CentOS and RHEL

# yum --enablerepo=remi,remi-php71 install php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

Start Apache HTTPD Service:

On Fedora

# systemctl start httpd.service

On CentOS and RHEL

# service httpd start
OR
# /etc/init.d/httpd start

Configure Nginx and PHP 7

Follow the below steps to configure Nginx and PHP 7. To do this you will need to edit nginx.conf file.

# vim /etc/nginx/nginx.conf

Now modify or append as follows:

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
                return 404;
        }
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
}

Save and close file.

Reload/Restart Nginx Server

# /etc/init.d/nginx reload

VERIFY PHP VERSION AND LOADED MODULES IN BROWSER

Create a phpinfo.php file with below content.

# vim /var/www/html/phpinfo.php
<?php

phpinfo();

?>

Save and exit.

Access phpinfo page in your browser.

http://localhost/phpinfo.php

Sample output:

php7.1-phpinfo-page

I hope this article will be helpful to install PHP 7 on RHEL/CentOS/Fedora/Ubuntu and Debian System. If you have any queries and problem please comment in comment section.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment