windows下安装php,nginx
本文介绍在windows下,安装PHP,并且使用nginx作为代理服务器。即windows+nginx+php
写在前面
在windows下php有一个FastCGI可以提供给NGINX使用。首先是php-cgi.exe -b 127.0.0.1:<port>启动php-cgi.exe,然后nginx配置fastcgi_pass 127.0.0.1:<port>;
一、下载、并安装nginx(懂的跳过)
1. 下载, NGINX for Win32
2.安装,解压,完成初步安装
二、下载php
1、下载phpWindows binaries of PHP
php有两个版本fastcgi使用Non Thread Safe,我们本次也是需要使用这个版本,下载后,将其解压到 C:\soft
2.下载RunHiddenConsole,并解压到C:\soft目录,如下图
三、配置nginx + php
在Nginx的目录下的conf目录下打开nginx.conf
.修改如下
#user nobody; worker_processes 1; # 打开log error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; # 打开log access_log logs/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; # 打开log access_log logs/host.access.log; location / { # 设置网站的根目录(类似Apache的www目录) # 这个路径自己定义就行,下面的是我自己的路径 root D:/www; # 把index.php添加到默认首页,就是输入/时自动打开/index.php index index.html index.htm index.php; } # 配置FastCGI,PHP 脚本请求全部转发到 FastCGI处理 location ~ \.php$ { # root D:/work/www; # 设置监听端口 fastcgi_pass 127.0.0.1:9000; # 设置nginx的默认首页文件(上面已经设置过了,可以删除) fastcgi_index index.php; # 设置脚本文件请求的路径 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 引入fastcgi的配置文件 include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } }
四、创建启动,关闭脚本,可以放在nginx安装目录
1.创建php-cgi.exe启动文件start-php-fcgi.bat
@ECHO OFF ECHO Starting PHP FastCGI... set PATH=C:\soft\php;%PATH% C:\soft\RunHiddenConsole.exe C:\soft\php\php-cgi.exe -b 127.0.0.1:9000
2.创建停止php-cgi文件stop-php-fcgi.bat
@ECHO off REM 结束进程 /F 强制终止 /IM 指定的进程 ECHO Stopping PHP FastCGI... TASKKILL /F /IM php-cgi.exe REM 关闭窗口 EXIT
3.创建nignx启动文件start.bat
nginx.exe
4.创建nginx停止文件stop.bat
taskkill /im nginx.exe /f
五、启动php、nginx
分别点击start-php-fcgi.bat、start.bat文件
六、测试
创建test.php,放到D:/www目录下
<?php echo phpinfo(); ?>
访问http://localhost/test.php,有如下内容,成功!