Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存)
2016-12-29 18:30
1006 查看
来源:http://blog.csdn.net/liuxinmingcode/article/details/50319145
LNMP
当前版本:PHP 5.5.7
为了体验PHP7的速度和性能,加上对新技术的热衷。但是直接切换是不明智的,可能会存在代码不兼容等等问题,因此准备编译安装PHP7,Nginx根据PHP-FastCGI监听端口启用哪个PHP版本。
FastCGI是一个可伸缩地、高速地在HTTP server和动态脚本语言间通信的接口。
大多数流行的HTTP server都支持FastCGI,包括Apache,Nginx和lighttpd等
当然PHP也在其中之列了。
FastCGI接口方式采用C/S结构,可以将HTTP服务器和脚本解析服务器分开,同时在脚本解析服务器上启动一个或多个脚本解析守护进程。当HTTP服务器每次遇到动态程序时,可以将其直接交付给FastCGI进程来执行,然后将其得到的结果返回给浏览器。
Nginx是通过PHP-FastCGI与PHP进行交互的。而PHP-FastCGI运行后会通过文件、或本地端口两种方式进行监听,在Nginx中配置相应的FastCGI监听端口或文件即实现Nginx请求对PHP的解释。
既然PHP-FastCGI是监听端口和文件的,那就可以让不同版本的PHP-FastCGI同时运行,监听不同的端口或文件,Nginx中根据需求配置调用不同的PHP-FastCGI端口或文件,即可实现不同版本PHP共存了。
2
3
1
2
3
注意:路径换成自己的。
我是编译到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
1
执行结果如下:
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/
php.ini、php-fpm.conf、www.conf和php-fpm脚本
2
3
4
5
1
2
3
4
5
启动php7-fpm
php-fpm支持的操作:
start,启动PHP的FastCGI进程。
stop,强制终止PHP的FastCGI进程。
quit,平滑终止PHP的FastCGI进程。
restart, 重启PHP的FastCGI进程。
reload, 重新加载PHP的php.ini。
logrotate, 重新启用log文件。
1
2
3
4
5
6
1
2
3
4
5
6
场景
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-master1
2
3
1
2
3
编译安装
注意:路径换成自己的。 我是编译到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 install1
1
执行结果如下:
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/目录下,自行修改配置1
2
3
4
5
1
2
3
4
5
启动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/profile1
1
修改Nginx配置,使用PHP7
location ~ .*.(php|php5)?$ { fastcgi_pass 127.0.0.1:9001; #注意,因为已经有个9000端口服务于PHP5版本了,所以PHP7就用9001了。 fastcgi_index index.php; include fcgi.conf; }1
2
3
4
5
6
1
2
3
4
5
6
相关文章推荐
- Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存)
- CentOS 7.x编译安装Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4 5.5 5.6 7.0 7.1多版本全能环境
- centos7.0-64位编译安装nginx+mysql+php
- 服务器基础搭建最全教程 CentOS 7.0编译安装 Nginx1.6.0 + MySQL5.6.19 + PHP5.6.30
- Centos7.0编译安装lnmp环境(nginx1.9.9+php7.1.6+mysql5.7.17)
- CentOS-6.5下编译安装LNMP环境【nginx1.8.1、mysql5.5.43、php 5.6】
- 虚拟机上CentOS 7.0编译安装Nginx+MySQL+PHP(二)
- 生产环境Centos LNMP编译安装nginx-1.6 MySQL-5.6 php-5.5
- CentOS5.6(64bit)下编译安装Nginx1.2.0、Percona-Server-5.1.61、PHP5.3.10
- Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.0 + Mariadb 10.1.9 + Nginx 1.9.9 + PHP 7.0.2)
- linux下编译安装nginx 1.x,php5.x,phpmyadmin 以及多版本php共存
- CentOS 7.0编译安装Nginx+MySQL+PHP
- CentOS 7.0编译安装Nginx+MySQL+PHP
- CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14
- CentOS 7源码编译安装PHP5.6和Nginx1.7.9及MySQL(搭建LNMP环境)
- CentOS 7.0编译安装Nginx+MySQL+PHP
- 64位 CentOS 5.6 中 Nginx + php + mysql 的编译安装
- CentOS6.6 32位 Minimal版本纯编译安装Nginx Mysql PHP Memcached
- 虚拟机上CentOS 7.0编译安装Nginx+MySQL+PHP(一)
- CentOS6.6 32位 Minimal版本纯编译安装Nginx Mysql PHP Memcached