PHP语言之Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存)
小标 2018-07-12 来源 : 阅读 1220 评论 0

摘要:本文主要向大家介绍了PHP语言之Centos+Nginx+PHP7.0编译安装,通过具体的实例向大家展示,希望对大家学习php语言有所帮助。

本文主要向大家介绍了PHP语言之Centos+Nginx+PHP7.0编译安装,通过具体的实例向大家展示,希望对大家学习php语言有所帮助。

场景

LNMP 
当前版本:PHP 5.5.7 
为了体验PHP7的速度和性能,加上对新技术的热衷。但是直接切换是不明智的,可能会存在代码不兼容等等问题,因此准备编译安装PHP7,Nginx根据PHP-FastCGI监听端口启用哪个PHP版本。

什么是FastCGI

FastCGI是一个可伸缩地、高速地在HTTP server和动态脚本语言间通信的接口。 
大多数流行的HTTP server都支持FastCGI,包括Apache,Nginx和lighttpd等 
当然PHP也在其中之列了。

FastCGI接口方式采用C/S结构,可以将HTTP服务器和脚本解析服务器分开,同时在脚本解析服务器上启动一个或多个脚本解析守护进程。当HTTP服务器每次遇到动态程序时,可以将其直接交付给FastCGI进程来执行,然后将其得到的结果返回给浏览器。

PHP版本共存思路

Nginx是通过PHP-FastCGI与PHP进行交互的。而PHP-FastCGI运行后会通过文件、或本地端口两种方式进行监听,在Nginx中配置相应的FastCGI监听端口或文件即实现Nginx请求对PHP的解释。

既然PHP-FastCGI是监听端口和文件的,那就可以让不同版本的PHP-FastCGI同时运行,监听不同的端口或文件,Nginx中根据需求配置调用不同的PHP-FastCGI端口或文件,即可实现不同版本PHP共存了。

编译安装过程

下载解压PHP7

wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/php-src/archive/master.zip

 

unzip -q php7-src-master.zip && cd php-src-master

编译安装

注意:路径换成自己的。 
我是编译到server/php7下面 
./buildconf –force 
./configure \ 
–prefix=/alidata/server/php7 \ 
–exec-prefix=/alidata/server/php7 \ 
–bindir=/alidata/server/php7/bin \ 
–sbindir=/alidata/server/php7/sbin \ 
–includedir=/alidata/server/php7/include \ 
–libdir=/alidata/server/php7/lib/php \ 
–mandir=/alidata/server/php7/php/man \ 
–with-config-file-path=/alidata/server/php7/etc \ 
–with-mysql-sock=/tmp/mysql.sock \ 
–with-mcrypt=/usr/include \ 
–with-mhash \ 
–with-openssl \ 
–with-mysql=shared,mysqlnd \ 
–with-mysqli=shared,mysqlnd \ 
–with-pdo-mysql=shared,mysqlnd \ 
–with-gd \ 
–with-iconv \ 
–with-zlib \ 
–enable-zip \ 
–enable-inline-optimization \ 
–enable-sockets \ 
–enable-soap \ 
–enable-session \ 
–with-curl \ 
–enable-opcache \ 
–enable-fpm \ 
–enable-fastcgi \ 
–with-fpm-user=www \ 
–with-fpm-group=www \ 
–disable-fileinfo

执行后结果如下(懒,就不截图了。哈哈): 
注:因为之前安装过PHP5版本,所以依赖关系就不需要了。

Generating files 
configure: creating ./config.status 
creating main/internal_functions.c 
creating main/internal_functions_cli.c 
+——————————————————————–+ 
| License: | 
| This software is subject to the PHP License, available in this | 
| distribution in the file LICENSE. By continuing this installation | 
| process, you are bound by the terms of this license agreement. | 
| If you do not agree with the terms of this license, you must abort | 
| the installation process at this point. | 
+——————————————————————–+ 
Thank you for using PHP. 
config.status: creating php7.spec 
config.status: creating main/build-defs.h 
config.status: creating scripts/phpize 
config.status: creating scripts/man1/phpize.1 
config.status: creating scripts/php-config 
config.status: creating scripts/man1/php-config.1 
config.status: creating sapi/cli/php.1 
config.status: creating sapi/fpm/php-fpm.conf 
config.status: creating sapi/fpm/www.conf 
config.status: creating sapi/fpm/init.d.php-fpm 
config.status: creating sapi/fpm/php-fpm.service 
config.status: creating sapi/fpm/php-fpm.8 
config.status: creating sapi/fpm/status.html 
config.status: creating sapi/cgi/php-cgi.1 
config.status: creating ext/phar/phar.1 
config.status: creating ext/phar/phar.phar.1 
config.status: creating main/php_config.h 
config.status: executing default commands 
configure: WARNING: unrecognized options: –with-mysql, –enable-fastcgi

编译&&安装

make clean && make && make install

执行结果如下:

nstalling shared extensions: /alidata/server/php7/lib/php/extensions/no-debug-non-zts-20151012/ 
Installing PHP CLI binary: /alidata/server/php7/bin/ 
Installing PHP CLI man page: /alidata/server/php7/php/man/man1/ 
Installing PHP FPM binary: /alidata/server/php7/sbin/ 
Installing PHP FPM config: /alidata/server/php7/etc/ 
Installing PHP FPM man page: /alidata/server/php7/php/man/man8/ 
Installing PHP FPM status page: /alidata/server/php7/php/php/fpm/ 
Installing phpdbg binary: /alidata/server/php7/bin/ 
Installing phpdbg man page: /alidata/server/php7/php/man/man1/ 
Installing PHP CGI binary: /alidata/server/php7/bin/ 
Installing PHP CGI man page: /alidata/server/php7/php/man/man1/ 
Installing build environment: /alidata/server/php7/lib/php/build/ 
Installing header files: /alidata/server/php7/include/php/ 
Installing helper programs: /alidata/server/php7/bin/ 
program: phpize 
program: php-config 
Installing man pages: /alidata/server/php7/php/man/man1/ 
page: phpize.1 
page: php-config.1 
Installing PEAR environment: /alidata/server/php7/lib/php/php/

设置PHP7的配置文件

php.ini、php-fpm.conf、www.conf和php-fpm脚本

cp php.ini-production /路径/php7/etc/php.ini #复制php.ini配置

cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm #复制php-fpm启动脚本

##其他配置都在php7/etc/目录下,自行修改配置

启动php7-fpm

chmod 755 /etc/init.d/php-fpm

/etc/init.d/php7-fpm start

php-fpm支持的操作:

· start,启动PHP的FastCGI进程。

· stop,强制终止PHP的FastCGI进程。

· quit,平滑终止PHP的FastCGI进程。

· restart, 重启PHP的FastCGI进程。

· reload, 重新加载PHP的php.ini。

· logrotate, 重新启用log文件。

添加PHP环境变量

echo -e '\nexport PATH=/路径/php7/bin:/路径/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile

修改Nginx配置,使用PHP7

location ~ .*.(php|php5)?$

        {

            fastcgi_pass  127.0.0.1:9001; #注意,因为已经有个9000端口服务于PHP5版本了,所以PHP7就用9001了。

            fastcgi_index index.php;

            include fcgi.conf;

·         }

以上就介绍了PHP的相关知识,希望对PHP有兴趣的朋友有所帮助。了解更多内容,请关注职坐标编程语言PHP频道!


本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程