#yum安装PHP编译时的依赖库
yum install libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel net-snmp net-snmp-devel openssl openssl-devel libcurl libcurl-devel
groupadd -r PHP && useradd -r -g PHP -s /bin/false -d /usr/local/PHP -M PHP
#下载与编译安装毫米库(mm lib)
#Download from http://www.ossp.org/pkg/lib/mm/
wget -c ftp://ftp.ossp.org/pkg/lib/mm/mm-1.4.1.tar.gz
tar zxvf mm-1.4.1.tar.gz
cd mm-1.4.1
./configure
make && make install
#下载与编译安装PHP
cd
wget -c http://mirrors.sohu.com/PHP/PHP-7.1.5.tar.bz2
tar jxvf PHP-7.1.5.tar.bz2
cd PHP-7.1.5
./configure \
--prefix=/usr/local/PHP \
--enable-bcmath \
--enable-mbstring \
--enable-sockets \
--enable-ctype \
--enable-opcache \
--enable-fpm \
--enable-MysqLnd \
--with-gd \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-libxml-dir \
--with-mm \
--with-gettext \
--with-snmp \
--with-openssl-dir \
--with-curl \
--with-fpm-user=Nginx \
--with-fpm-group=Nginx \
--with-MysqL-sock=/var/lib/MysqL/MysqL.sock
make && make install
#选做步骤:执行make test命令进行测试
#make test
#查看编译成功后的PHP安装目录(需要确保至少存在MysqLi.so、pdo_MysqL.so这两个动态库文件)
ls -lrt /usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20160303/
#设置PHP7的配置文件跟脚本PHP.ini、PHP-fpm.conf、www.conf、PHP-fpm
cp PHP.ini-production /usr/local/PHP/etc/PHP.ini
cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf
cp /usr/local/PHP/etc/PHP-fpm.d/www.conf.default /usr/local/PHP/etc/PHP-fpm.d/www.conf
cp -R ./sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm
echo -e '\nexport PATH=/usr/local/PHP/bin:/usr/local/PHP/sbin:$PATH\n' >> /etc/profile && source /etc/profile
#设置PHP日志目录和PHP-fpm的运行进程ID文件(PHP-fpm.sock)目录
mkdir -p /var/log/PHP-fpm/ && mkdir -p /var/run/PHP-fpm && cd /var/run/ && chown -R Nginx:Nginx PHP-fpm
#修改session的目录配置
mkdir -p /var/lib/PHP/session && chown -R Nginx:Nginx /var/lib/PHP
#配置开机自启动,增加到主机sysV服务
chmod +x /etc/init.d/PHP-fpm
chkconfig --add PHP-fpm
chkconfig PHP-fpm on
PHP-fpm -t
#启动PHP服务
service PHP-fpm start
#查看PHP-FPM进程
ps -aux|grep PHP-fpm
#查看PHP7版本信息
PHP -v
原文链接:https://www.f2er.com/centos/377268.html