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

歡迎訪問 生活随笔!

生活随笔

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

php

nginx php7 fastcgi,Windows下搭建PHP7+FastCGI+Nginx环境

發布時間:2024/10/6 php 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx php7 fastcgi,Windows下搭建PHP7+FastCGI+Nginx环境 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注意這里說的是FastCGI,不是FPM,FPM全稱是FastCGI Process Manager,它是FastCGI進程管理器,在Windows下是沒有這個的,只能手動啟動FastCGI進程由它自己維護(沒有管理器)。自己電腦上用的是PHP 5.6 + Apache 2.4,由于PHP 7.1都出來了,一些新特性得學習,于是決定再搭一個環境。當然的就選了標題里邊的組合。

PHP官網下載PHP 7.1 的windows包,這里選擇的是php-7.1.0-nts-Win32-VC14-x64,解壓后可以看到跟php.exe同級的目錄下有php-cgi.exe,啟動FastCGI就需要使用它。

Nginx官網下載

server {

listen 8080;

server_name test.nginx.com;

root E:/amp/nginx-1.11.8/html/test;

location / {

index index.html index.htm index.php;

try_files $uri $uri/ /index.php$is_args$args;#不需要單入口重寫,不需要這句

}

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9123;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

access_log E:/amp/nginx-1.11.8/logs/test/access.log;

error_log E:/amp/nginx-1.11.8/logs/test/error.log;

}

由于Apache 2.4使用了80端口,這里便使用8080端口了。PHP FastCGI將會使用9123端口。用命令行進入nginx.exe所有目錄,執行:start nginx即可啟動Nginx。其他命令如nginx -s stop|quit|reopen|reload等跟Linux下是一樣的。

E:\amp\nginx-1.11.8>nginx -h

nginx version: nginx/1.11.8

Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:

-?,-h : this help

-v : show version and exit

-V : show version and configure options then exit

-t : test configuration and exit

-T : test configuration, dump it and exit

-q : suppress non-error messages during configuration testing

-s signal : send signal to a master process: stop, quit, reopen, reload

-p prefix : set prefix path (default: NONE)

-c filename : set configuration file (default: conf/nginx.conf)

-g directives : set global directives out of configuration file

下邊就是啟動PHP FastCGI了。也簡單,命令行進入php-cgi.exe所在目錄,執行以下代碼即可:

php-cgi.exe -b 127.0.0.1:9123 -c php.ini

-b 即是綁定哪個IP與端口,-c 使用哪個配置文件。這樣子啟動后,命令行窗口不能做其他 操作也不能關閉,一關閉進程也關閉了。這時候需要借助一個小小的工具:

RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9123 -c php.ini

或許覺得這樣子麻煩,那么可以把它寫成bat腳本,每次要啟動雙擊執行就可以了,或者添加到開機啟動,有需要的可以參照參考鏈接來弄了。我覺得手動執行一下也不是很麻煩。啟動后從任務管理器可以看到。

最后,添加域名到host文件,在網站根目錄創建index.php輸出phpinfo(),訪問http://test.nginx.com:8080,即可看到最終成果:

這樣,就可以愉快的使用PHP 7.1與PHP 5.6了。

update at 2017-06-27

為方便啟動,可以寫一個bat文件完成FastCGI與nginx的啟動。注意bat文件中定義變量=兩邊不能有空格

#啟動start.bat

@echo off

set nginx_path=E:\nginx-1.13.1

set php_path=E:\php-5.6.30-Win32-VC11-x86

set port=9123

echo Starging PHP FastCGI at 127.0.0.1:%port%...

%nginx_path%\RunHiddenConsole.exe %php_path%\php-cgi.exe -b 127.0.0.1:%port% -c %php_path%\php.ini

echo Starging nginx...

%nginx_path%\RunHiddenConsole.exe %nginx_path%\nginx.exe

echo Done !

exit

#關閉stop.bat

@echo off

echo Stopping nginx...

taskkill /F /IM nginx.exe > nul

echo Stopping PHP FastCGI...

taskkill /F /IM php-cgi.exe > nul

exit

在windows計劃任務中添加一個任務在開機時運行start.bat,這樣就更多方便了。

總結

以上是生活随笔為你收集整理的nginx php7 fastcgi,Windows下搭建PHP7+FastCGI+Nginx环境的全部內容,希望文章能夠幫你解決所遇到的問題。

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