1.更新Cenos7系统依赖
yum install -y git gcc gcc-c++ libxml2-devel pkgconfig openssl-devel bzip2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf bison re2c libicu-devel
2.下载源码包并解压
wget -O /usr/src/php-7.2.0.tar.gz http://php.net/get/php-7.2.0.tar.gz/from/this/mirror
cd /usr/src
tar zxvf php-7.2.0.tar.gz
3.配置安装php
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-config-file-scan-dir=/usr/local/php7/etc/conf.d --enable-bcmath --with-bz2 --with-curl --enable-filter --enable-fpm --with-gd --enable-gd-native-ttf --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-intl --enable-mbstring --with-mcrypt --enable-mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --disable-phpdbg --disable-phpdbg-webhelper --enable-opcache --with-openssl --enable-simplexml --with-sqlite3 --enable-xmlreader --enable-xmlwriter --enable-zip --with-zlib
make && make install
4.配置php-fpm(fastcgi进程管理器)
4.1 创建conf.d目录, 添加配置文件
mkdir /usr/local/php7/etc/conf.d
cp php.ini-production /usr/local/php7/lib/php.ini
cp sapi/fpm/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm.conf /usr/local/php7/etc/php-fpm.conf
4.2 创建并编辑/usr/local/php7/etc/conf.d/modules.ini文件,添加zend_extension=opcache.so
4.3 编辑/usr/local/php7/etc/php–fpm.d/www.conf,更新配置如下
user = nobody
group = nobody
listen.owner = nginx
listen.group = nginx
4.4 为php-fpm创建符号链接
ln –s /usr/local/php7/sbin/php–fpm /usr/sbin/php–fpm
5. 为php-fpm创建服务
5.1 创建并编辑/usr/lib/systemd/system/php–fpm.service,添加
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm/php-fpm.pid
ExecStart=/usr/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
5.2 创建运行目录,开机启动服务
mkdir /run/php–fpm
systemctl start php-fpm