How to install PHP 7.2 on CentOS 7/RHEL 7

How do I Install PHP 7.2 on CentOS 7 server? How can I setup and install PHP 7.2 on RHEL 7 server along with Nginx web server? How do I configure PHP-fpm version 7.2 with Nginx server running on a CentOS / Red Hat Enterprise Linux version 7?

PHP is a recursive acronym for PHP: Hypertext Preprocessor. It is server-side scripting. One can write dynamically generated web pages in PHP or embedded PHP directly into HTML. PHP offers built-in database integration for several commercial and non-commercial database management systems. By default, CentOS 7/RHEL 7 comes with PHP version 5.4 only. This page shows how to install PHP 7.2 on CentOS 7 or RHEL 7 server using yum command.
ADVERTISEMENTS

Installing PHP version 7.2

The procedure to install PHP 7.2 on CentOS 7 or RHEL 7 is as follows:

  1. Turn on EPEL repo, enter:
    sudo yum -y install epel-release
  2. Turn on Remi repo i.e.remi-php72:
    sudo yum-config-manager –enable remi-php72
  3. Refresh repository:
    sudo yum update
  4. Install php version 7.2, run:
    sudo yum install php

Let us see examples and syntax is details.

How to 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

Fig.01: Installing epel-release package on a Centos 7
Fig.01: Installing epel-release package on a Centos 7

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

Install remi repo for PHP 7.2 on CentOS 7

Install yum-utils packages too:
$ sudo yum install yum-utils

How to install yum-utils on CentOS/RHEL using yum command

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'

Sample outputs

php72-php-fpm.x86_64 : PHP FastCGI Process Manager php72-php-gd.x86_64 : A module for PHP applications for using the gd graphics php72-php-mysqlnd.x86_64 : A module for PHP applications that use MySQL php72-php-pecl-mysql.x86_64 : MySQL database access functions php72-php-pecl-mysql-xdevapi.x86_64 : MySQL database access functions
Install PHP 7.2 on CentOS 7

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

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

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
Sample outputs:

[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zlib

[Zend Modules]
Zend OPcache

Turn on PHP fpm for nginx

Use systemctl command:
$ sudo systemctl enable php72-php-fpm.service
Sample outputs:

Created symlink from /etc/systemd/system/multi-user.target.wants/php72-php-fpm.service to /usr/lib/systemd/system/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

systemctl status php72-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 fileRestart 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
Create a test script called foo.php at /usr/share/nginx/html/
$ sudo vi /usr/share/nginx/html/foo.php
Append the following code:

<?php // test script for CentOS/RHEL 7+PHP 7.2+Nginx phpinfo(); ?>
Nginx with PHP 7.2 running on a RHEL 7 or CentOS 7 server

Save and close the file. Fire a browser and type url:
http://your-domain-name/foo.php
http://10.21.136.134/foo.php

Sample outputs:

source : https://www.cyberciti.biz/faq/how-to-install-php-7-2-on-centos-7-rhel-7/

Posted on: August 29, 2020, by :  | 163 views
https://serang.ut.ac.id/css/css/slot88/ https://tinjut.bagkeu.dikdasmen.kemdikbud.go.id/slot-maxwin/ https://dpm.polinema.ac.id/slot-gacor/ https://akademik.ft.unm.ac.id/slot-dana/ https://ppdb.probolinggokab.go.id/slot-5000/ https://bkad.sulselprov.go.id/assets/ https://ojs.balidwipa.ac.id/docs/slot-gacor/ http://korpri.pekalongankab.go.id/api/slot-gacor/ https://elang.umpp.ac.id/foto/farmasi/-/asset/ http://rsud-kelet.jatengprov.go.id/wp-content/-/asset/ https://kusdhianto-fe.staff.ugm.ac.id/slot88/ http://ppdb.probolinggokab.go.id/judi-bola/ https://bapenda.labuhanbatukab.go.id/racikan-sbobet/ http://rsud-kelet.jatengprov.go.id/wp-content/-/data/ https://agenda.riau.go.id/-/judi-bola/ https://balapan.padang.go.id/sbobet88/ http://jdih.wakatobikab.go.id/sbobet88/ http://kph.menlhk.go.id/sbobet88/ https://bkad.sulselprov.go.id/data/ https://dpm.polinema.ac.id/slot-gacor/ https://dinkes.jemberkab.go.id/storage/attachments/