日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存)

發布時間:2024/9/20 php 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

來源:http://blog.csdn.net/liuxinmingcode/article/details/50319145

場景

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.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

執行后結果如下(懶,就不截圖了。哈哈):?
注:因為之前安裝過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
  • 1
  • 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/profile
  • 1
  • 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老版本共存)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。