编译安装php7

1、下载并解压php7

cd /home/zlfzy/tmp
wget https://zlfapp.oss-cn-shenzhen.aliyuncs.com/php-7.0.18.tar.gz
tar xf php-7.0.18.tar.gz
cd php-7.0.18

2、安装一些依赖包

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel

3、编译参数

./configure --prefix=/home/zlfzy/app/php7 \
--with-config-file-path=/home/zlfzy/app/php7/etc \
--with-config-file-scan-dir=/home/zlfzy/app/php7/etc/php.d \
--with-mcrypt=/usr/include \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-gd \
--with-iconv \
--with-zlib \
--enable-xml \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache

4、完成编译

make 
make install

5、调整php配置

cp php.ini-production /home/zlfzy/app/php7/etc/php.ini
vi /home/zlfzy/app/php7/etc/php.ini
######避免PHP信息暴露在http头中
expose_php = Off

######避免暴露php调用mysql的错误信息
display_errors = Off

######在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置)
log_errors = On

######设置PHP的扩展库路径
extension_dir = "/home/zlfzy/app/php7/lib/php/extensions/no-debug-non-zts-20151012/"

######设置PHP的opcache和mysql动态库
zend_extension=opcache.so
extension=mysql.so
extension=pdo_mysql.so

######设置PHP的时区
date.timezone = PRC

注意:要确保/home/zlfzy/app/php7/lib/php/extensions/no-debug-non-zts-20151012/里面有pdo_mysql.so和mysql.so,没有的话要另外安装

a、安装mysql.so扩展
cd /home/zlfzy/tmp
yum -y install git
git clone https://github.com/php/pecl-database-mysql     mysql   --recursive
cd mysql
/home/zlfzy/app/php7/bin/phpize
./configure --with-php-config=/home/zlfzy/app/php7/bin/php-config
make
make install
最后添加到php.ini中
extension=mysql.so

b、安装pdo_mysql.so扩展
cd /home/zlfzy/tmp/php-7.0.18/ext/pdo_mysql
/home/zlfzy/app/php7/bin/phpize
yum install autoconf -y
./configure --with-php-config=/home/zlfzy/app/php7/bin/php-config --with-pdo-mysql=/home/zlfzy/app/mysql
make
make install
echo 'extension="pdo_mysql.so"' >> /home/zlfzy/app/php7/etc/php.ini

6、添加php环境变量

export PATH=/home/zlfzy/app/php7/bin:/home/zlfzy/app/php7/sbin:$PATH
source /etc/profile

7、php -m 看看有没有pdo_mysql

8、启用php-fpm服务

cd /home/zlfzy/app/php7/etc
mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf
cd /home/zlfzy/tmp/php-7.0.18/sapi/fpm
ls
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
通过上面这个操作,我们就可以使用service php-fpm start来启用php-fpm了。用ps -ef | grep php-fpm看看进程吧

9、配置nginx

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
    include        fastcgi_params;
}
上面是nginx.conf给出的默认配置,一般情况下自己调整一下就可以用了
添加新评论