本文操作环境:CentOS Linux release 7.6.1810 (Core)

指令记录如下:

#安装PHP依赖的软件包
yum install autoconf gcc gcc-c++ wget curl curl-devel cmake libpng libpng-devel libjpeg libjpeg-devel libzip libzip-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel freetype freetype-devel libicu-devel libxslt libxslt-devel

#添加www组和www账户
groupadd www
useradd -g www www

#下载php7.2.15(下载地址可能有变,自己去php.net获取最新地址)
wget http://120.52.51.15/cn2.php.net/distributions/php-7.2.15.tar.gz

#解压
tar xf php-7.2.15.tar.gz

#进入源代码目录
cd php-7.2.15/

#配置,指定安装目录为/usr/local/web/php
./configure --prefix=/usr/local/web/php --with-config-file-path=/usr/local/web/php/etc --enable-bcmath --enable-fpm --enable-ftp --enable-inline-optimization --enable-intl --enable-libxml --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --with-bz2 --with-curl --with-fpm-group=www --with-fpm-user=www --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-jpeg-dir --with-libdir=lib64 --with-libxml-dir --with-mhash --with-mysqli=mysqlnd --with-openssl --with-pcre-regex --with-pdo-mysql=mysqlnd --with-png-dir --with-xmlrpc --with-xsl --with-zlib

#如无报错,即可执行编译(如果报错,则执行make clean清理,解决后重新make)
make

#编译完毕安装
make install

#添加php-fpm服务管理脚本
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

#设置php-fpm服务开机自启动
systemctl enable php-fpm

#生成配置文件(如果用于生产环境则应该复制php.ini-production)
cp php.ini-development /usr/local/web/php/etc/php.ini

#进入配置文件目录
cd /usr/local/web/php/etc

#配置php-fpm
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf

#设置默认时区
echo 'date.timezone = "Asia/Shanghai"' >> php.ini