Install PHP 7.2 on CentOS 7

Turn on EPEL repo on a CentOS and RHEL 7.x sever by typing the following command:


$ sudo yum install epel-release



Turn remi repo too:


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


Install yum-utils packages too:


$ sudo yum install yum-utils


Enable remi repo, run:


$ sudo yum-config-manager --enable remi-php72
$ sudo yum update


Search for PHP 7.2 packages and modules with more command/grep command/egrep command:


$ sudo yum search php72 | more
$ sudo yum search php72 | egrep 'fpm|gd|mysql|memcache'


Finally, install php 7.2 on CentOS 7.2:


$ sudo yum install php72

You must install “PHP FastCGI Process Manager” called php72-php-fpm along with commonly used modules:


$ sudo yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache


How to install PHP 7.2 on RHEL 7

The steps are as follows to enable and install PHP 7.2 on RHEL 7 using yum command:


$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ sudo yum install yum-utils
$ sudo subscription-manager repos --enable=rhel-7-server-optional-rpms
$ sudo yum-config-manager --enable remi-php72
$ sudo yum update
$ sudo yum search php72 | more
$ sudo yum install php72 php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache

 

Verification

Check PHP version:


$ php --version


Sample output:

PHP 7.2.1 (cli) (built: Jan  3 2018 07:51:38) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.2.1, Copyright (c) 1999-2017, by Zend Technologies



List installed modules


$ php72 --modules

Turn on PHP fpm for nginx

Use systemctl command:


$ sudo systemctl enable php72-php-fpm.service



Commands to control PHP fpm:


Start PHP fpm service

$ sudo systemctl start php72-php-fpm.service


Stop PHP fpm service

$ sudo systemctl stop php72-php-fpm.service


Restart PHP fpm service

$ sudo systemctl restart php72-php-fpm.service


Get status of PHP fpm service

$ sudo systemctl status php72-php-fpm.service



Configure Nginx for using with PHP 7.2

Make sure latest version of Nginx server installed on CentOS 7 or RHEL 7. Find out nginx server user and group names using egrep command


$ egrep '^(user|group)' /etc/nginx/nginx.conf

Sample outputs:


user  nginx;



Edit vi /etc/opt/remi/php72/php-fpm.d/www.conf:


$ sudo vi /etc/opt/remi/php72/php-fpm.d/www.conf


Set user and group to nginx:


user = nginx
group = nginx

Save and close the file. Restart php-fpm service:


$ sudo systemctl restart php72-php-fpm.service

Update your nginx config


$ sudo vi /etc/nginx/conf.d/default.conf

Edit/add as follows in server section:

    ## enable php support ##
    location ~ \.php$ {
        root /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }


Save and close the file. Restart the nginx server:


$ sudo systemctl restart nginx

 

Was this answer helpful? 1 Users Found This Useful (2 Votes)