如果你的服务器里已经装过低版本的php,可以先跳过此步,后面编译php7的时候,如果报错,再根据错误提示,再来安装,如果不嫌麻烦的话

yum install php-mcrypt libmcrypt libmcrypt-devel libxml2-devel \

openssl-devel libcurl-devel \

libjpeg.x86_64 libpng.x86_64 libjpeg-devel.x86_64 \

libpng-devel.x86_64 libjpeg-turbo-devel\

freetype.x86_64 freetype-devel.x86_64 \

libmcrypt-devel mysql-devel -y

我的php7是计划装在 /server/php7/目录下,之前的是在/server/php/目录下

下载编译php7

cd /server/

wget http://cn2.php.net/distributions/php-7.0.0.tar.gz

tar zxvf php-7.0.0.tar.gz

cd php-7.0.0

./configure --prefix=/server/php7 \

--with-config-file-path=/server/php7/etc \

--with-mcrypt \

--with-mcrypt \

--enable-mysqlnd --with-gd \

--with-iconv=/usr/local/libiconv \

--with-zlib \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--enable-ftp \

--enable-gd-native-ttf \

--with-openssl \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--with-gettext \

--with-curl \

--with-jpeg-dir \

--with-freetype-dir \

--with-mysqli \

--enable-embedded-mysqli \

--with-pdo-mysql

make

make install

配置php

cp php.ini-production /server/php7/etc/php.ini

cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm //是为了和之前的不冲突

chmod +x /etc/init.d/php7-fpm

cp /server/php7/etc/php-fpm.conf.default /server/php7/etc/php-fpm.conf

cp /server/php7/etc/php-fpm.d/www.conf.default /server/php7/etc/php-fpm.d/www.conf

vim /server/php7/etc/php.ini

加入
zend_extension=/server/php7/lib/php/extensions/no-debug-non-zts-20151012/opcache.so

vim /server/php7/etc/php-fpm.d/www.conf //修改子进程用户

user = nobody

group = nobody

修改为

user = www

group = www

启动
/etc/init.d/php7-fpm start //如果之前有老的php版本,记得先关掉

我之前的php版本是加入的系统自启动,所有还得修改

vim /etc/rc.d/rc.local

修改为

/etc/init.d/php-fpm start
/etc/init.d/php7-fpm start

还有之前我吧php命令加入到了环境变量,还需要修改

vim /etc/profile

修改为

export PATH=$PATH:/server/mysql/bin:/server/nginx/sbin:/server/php7/sbin:/server/php7/bin

为了安全最好是去掉头信息 X-Powered-By: PHP/7..
则修改 php.ini 文件 设置 expose_php = Off
vim /server/php7/etc/php.ini
找到 expose_php = On
改为 expose_php = Off