centos7下编译安装php-7.0.15(PHP-FPM)
一、下载php7源码包
http://php.net/downloads.php
如:php-7.0.15.tar.gz
二、安装所需依赖
> yum -y install gd-devel zlib-devel libjpeg-devel libpng-devel libiconv-devel freetype-devel libxml2 libxml2-devel openssl openssl-devel curl-devel libxslt-devel libmcrypt-devel mhash mcrypt
如果无法安装libiconv,请手动下载安装
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
> tar xf libiconv-1.14.tar.gz
> cd libiconv-1.14
> ./configure --prefix=/usr/local/libiconv
> make && make install
如果出现如下问题,说明你系统版本较高。
./stdio.h:1010:1: 错误:‘gets’未声明(不在函数内)
> cd srclib/
> sed -i -e '/gets is a security/d' ./stdio.in.h
> cd ../
> make && make install
如果安装libmcrypt-devel、mhash、mcrypt出错,则重新配置yum源。
http://mirrors.163.com/.help/centos.html
http://mirrors.aliyun.com/help/centos
三、编译PHP
创建账号
> useradd -s /sbin/nologin -M nginx
> tar xf php-7.0.15.tar.gz
> cd /data/php-7.0.15
> ./configure --prefix=/data/php7 \
--with-openssl \
--with-pcre-regex \
--with-kerberos \
--with-libdir=lib \
--with-libxml-dir \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-sqlite \
--with-gd \
--with-iconv \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-gettext \
--with-curl \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-mysqlnd \
--enable-zip \
--enable-inline-optimization \
--enable-shared \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-opcache \
--enable-fpm \
--enable-maintainer-zts \
--enable-fileinfo \
四、make && make install
> make && make install
五、配置文件
> cp /data/php-7.0.15/php.ini-development /data/php7/lib/php.ini
> cp -R /data/php-7.0.15/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
> cp /data/php7/etc/php-fpm.conf.default /data/php7/etc/php-fpm.conf
> cp /data/php7/etc/php-fpm.d/www.conf.default /data/php7/etc/php-fpm.d/www.conf
六、修改php.ini
> mkdir /data/php7/tmp
> chmod 766 /data/php7/tmp
extension_dir = "/data/php7/lib/php/extensions/no-debug-zts-20151012/"
session.save_path = "/data/php7/tmp"
date.timezone = PRC
七、添加环境变量
> echo 'export PATH=/data/php7/bin:/data/php7/sbin:$PATH' >> /etc/profile
> source /etc/profile
八、添加自启动
> chkconfig --add php-fpm
> chkconfig php-fpm on
> chkconfig --list php-fpm
九、启动服务
> chmod 755 /etc/init.d/php-fpm
> service php-fpm start
> ps -ef|grep php-fpm
十、php-fpm重启
php-fpm的pid文件默认在你php安装目录下var/run/php-fpm.pid
当然这是可以更改的,在/data/php7/etc/php-fpm.conf文件中
关闭
> kill -INT `cat /data/php7/var/run/php-fpm.pid`
重启
> kill -USR2 `cat /data/php7/var/run/php-fpm.pid`