Home >Backend Development >PHP Tutorial >The simplest Nginx+PHP
Note:
1. Only used in Windows 7 environment, date is 2015-8-11, other environments are for reference only.
2. Only provide the simplest configuration
Quick installation and configuration
nginx.conf
: <code>server { # 替换为需要的端口 listen 80<span>;</span> server_name localhost<span>;</span> # 替换为需要的目录 root D:/Projects/nginx-html<span>;</span> index index.html index.htm index.php<span>;</span> location ~ \.php$ { include fastcgi.conf<span>;</span> # 连接到本机 PHP FastCGI Server 开启的端口 fastcgi_pass 127.0.0.1:9001<span>;</span> } }</code>
nginx
and php-cgi
are located to the Path environment variable nginx
server block location block fastcgi_pass
Configuration is consistent<code>php<span>-cgi</span><span>-b</span><span>127.0</span><span>.0</span><span>.1</span>:<span>9001</span></code>
<code><span><?php</span><span>echo</span><span>"<h1>PHP works!</h1>"</span>;</code>
The configured address and port (for example
http://localhost:80/index.php), and seeing "PHP works!" indicates success!
, and write
<code>@echo off echo Starting php-cgi <span>...</span> RunHiddenConsole php-cgi -b <span>127.0</span><span>.0</span><span>.1</span>:<span>9001</span> echo Starting nginx <span>...</span> c: cd C:\Program Files\nginx-<span>1.9</span><span>.3</span> RunHiddenConsole nginx pause</code>
and write
<code>@echo off echo Reloading Nginx <span>...</span> c: cd C:\Program Files\nginx-<span>1.9</span><span>.3</span> nginx -s reload pause</code>
and write
<code>@echo off echo Closing php-cgi <span>...</span> taskkill /IM php-cgi.exe echo Closing nginx <span>...</span> c: cd C:\Program Files\nginx-<span>1.9</span><span>.3</span> nginx -s quit pause</code>
,
nginx-reload,
nginx-quit can quickly start, restart, and shut down Nginx service and php-cgi
Reference:1. How to correctly configure Nginx+PHP
2. Installation and configuration method of Nginx+PHP5 under Windows