Windows 下 Nginx 配置 PHP 环境
Windows 下 Nginx 配置 PHP 环境
PHP
下载 PHP
PHP 下载地址,下载 x64 Thread Safe 的 Zip 文件。然后随便解压到一个目录。
解压后在文件夹中找到php.ini-development
文件复制一份并改名为php.ini
.
给PHP指定可加载扩展模块的位置
在php.ini
中找到extension_dir
项目,取消注释并赋值为./ext
:
修改前:
; Directory in which the loadable extensions (modules) reside.
; https://php.net/extension-dir
;extension_dir = "./"
; On windows:
;extension_dir = "ext"
修改后:
; Directory in which the loadable extensions (modules) reside.
; https://php.net/extension-dir
;extension_dir = "./"
; On windows:
extension_dir = "./ext"
配置 PATH_INFO
在php.ini
中找到cgi.fix_pathinfo
项目,取消注释:
修改前:
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; https://php.net/cgi.fix-pathinfo
;cgi.fix_pathinfo=1
修改后:
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; https://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=1
Nginx
下载 Nginx
Nginx 下载地址,下载nginx/windows-x.xx.x
版本,下载完解压到目录。
配置 PHP
打开 nginx 目录中的conf
的nginx.conf
文件:
在server
配置 FastCGI:
原本的配置文件这一段直接就有,是注释着的,打开注释,然后修改fastcgi_param
那一行就行了。
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
配置开机自启
在 nginx 目录创建一个 txt 文件,粘贴一下内容:
@echo off
start /b "" "nginx.exe"
exit
然后重命名为start-nginx.bat
,并创建一个快捷方式。
在 php 目录创建一个 txt 文件,粘贴一下内容:
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "php-cgi.exe -b 127.0.0.1:9000 -c php.ini", 0, False
Set objShell = Nothing
然后重命名为start-php-cgi.vbs
,并创建一个快捷方式。
快捷键Win + r
并输入shell:startup
回车打开自启目录,将两个快捷方式粘贴进去即可开机自启。