安装php7,与php5共存

发布时间:2019-08-07 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了安装php7,与php5共存脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

起步

之前在服务器搭建了lamp环境,想换用性能更强的nginx作为服务器软件,又想将php5升级为php7.
安装nginx无需赘述:sudo apt-get install nginx,启动ng前修改apache的端口。

安装php7

码在http://php.net/downloads.php 下载,并解压。

# cd php7***
# ./configure --PRefix=/usr/local/php7 --wITh-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --with-MySQL=mySQLnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-XMl --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 --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-Opcache

# make
# make install

为不与5冲突,文件夹都用php7,安装过程中报错的安装响应的依赖。

对接nginx

nginx本身不能处理phP脚本,需要发给php解释器处理。nginx一般是把请求发fastcgi管理进程处理,fascgi管理进程选择cgi子进程处理结果并返回被nginx。

# cp php.ini-production /usr/local/php7/etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
# chmod +x /etc/init.d/php7-fpm
# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

启动php-fpm

# service php7-fpm start

中途如遇到日志文件路径不存在就手动创建并给予写的权限。

# service php7-fpm start
Starting php-fpm [07-Apr-2016 11:16:11] ERROR: [pool www] cannot get gid for group 'nobody'
[07-Apr-2016 11:16:11] ERROR: FPM initialization failed
 failed

遇到这个错误时,要添加个nobody组groupadd nobody再重新启动。

nginx的配置

这是访问php文件是变成下载文件,因为ng并未配置响应处理。

location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_SCRIPT_NAME;
            include        fastcgi_params;
        }

Thank you for using PHP.

脚本宝典总结

以上是脚本宝典为你收集整理的安装php7,与php5共存全部内容,希望文章能够帮你解决安装php7,与php5共存所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。