Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存)
來源:http://blog.csdn.net/liuxinmingcode/article/details/50319145
場(chǎng)景
LNMP?
當(dāng)前版本:PHP?5.5.7?
為了體驗(yàn)PHP7的速度和性能,加上對(duì)新技術(shù)的熱衷。但是直接切換是不明智的,可能會(huì)存在代碼不兼容等等問題,因此準(zhǔn)備編譯安裝PHP7,Nginx根據(jù)PHP-FastCGI監(jiān)聽端口啟用哪個(gè)PHP版本。
什么是FastCGI
FastCGI是一個(gè)可伸縮地、高速地在HTTP server和動(dòng)態(tài)腳本語言間通信的接口。?
大多數(shù)流行的HTTP server都支持FastCGI,包括Apache,Nginx和lighttpd等?
當(dāng)然PHP也在其中之列了。
FastCGI接口方式采用C/S結(jié)構(gòu),可以將HTTP服務(wù)器和腳本解析服務(wù)器分開,同時(shí)在腳本解析服務(wù)器上啟動(dòng)一個(gè)或多個(gè)腳本解析守護(hù)進(jìn)程。當(dāng)HTTP服務(wù)器每次遇到動(dòng)態(tài)程序時(shí),可以將其直接交付給FastCGI進(jìn)程來執(zhí)行,然后將其得到的結(jié)果返回給瀏覽器。
PHP版本共存思路
Nginx是通過PHP-FastCGI與PHP進(jìn)行交互的。而PHP-FastCGI運(yùn)行后會(huì)通過文件、或本地端口兩種方式進(jìn)行監(jiān)聽,在Nginx中配置相應(yīng)的FastCGI監(jiān)聽端口或文件即實(shí)現(xiàn)Nginx請(qǐng)求對(duì)PHP的解釋。
既然PHP-FastCGI是監(jiān)聽端口和文件的,那就可以讓不同版本的PHP-FastCGI同時(shí)運(yùn)行,監(jiān)聽不同的端口或文件,Nginx中根據(jù)需求配置調(diào)用不同的PHP-FastCGI端口或文件,即可實(shí)現(xiàn)不同版本PHP共存了。
編譯安裝過程
下載解壓PHP7
wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/php-src/archive/master.zipunzip -q php7-src-master.zip && cd php-src-master- 1
- 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
執(zhí)行后結(jié)果如下(懶,就不截圖了。哈哈):?
注:因?yàn)橹鞍惭b過PHP5版本,所以依賴關(guān)系就不需要了。
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- 1
- 1
執(zhí)行結(jié)果如下:
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/
設(shè)置PHP7的配置文件
php.ini、php-fpm.conf、www.conf和php-fpm腳本
cp php.ini-production /路徑/php7/etc/php.ini #復(fù)制php.ini配置cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm #復(fù)制php-fpm啟動(dòng)腳本##其他配置都在php7/etc/目錄下,自行修改配置- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
啟動(dòng)php7-fpm
chmod 755 /etc/init.d/php-fpm /etc/init.d/php7-fpm startphp-fpm支持的操作:
- start,啟動(dòng)PHP的FastCGI進(jìn)程。
- stop,強(qiáng)制終止PHP的FastCGI進(jìn)程。
- quit,平滑終止PHP的FastCGI進(jìn)程。
- restart, 重啟PHP的FastCGI進(jìn)程。
- reload, 重新加載PHP的php.ini。
- logrotate, 重新啟用log文件。
添加PHP環(huán)境變量
echo -e '\nexport PATH=/路徑/php7/bin:/路徑/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile- 1
- 1
修改Nginx配置,使用PHP7
location ~ .*.(php|php5)?${fastcgi_pass 127.0.0.1:9001; #注意,因?yàn)橐呀?jīng)有個(gè)9000端口服務(wù)于PHP5版本了,所以PHP7就用9001了。fastcgi_index index.php;include fcgi.conf;}- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
總結(jié)
以上是生活随笔為你收集整理的Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 统计Apache或nginx日志里访问次
- 下一篇: 请问领航M5轻卡运货可以装多少啊?谢谢了