As a lightweight WEB server supporting PHP, Nginx has received more and more applications in PHP website construction. Recently, Nginx + PHP5 running environment has been installed and configured on Windows platform, which is very convenient, the following is a detailed tutorial on how to configure PHP5 for Nginx in Windows. Nginx configures PHP In FastCgi mode.
Download Nginx
Nginx can be installed on a variety of operating systems. I use Windows, so you need to download the Nginx Windows version and click to download Nginx. The nginx/Windows-0.8.53 version is downloaded.
Install Nginx
After Nginx is downloaded, Nginx needs to be installed in Windows. It is very convenient to install Nginx in Windows. After decompression, copy the file to the C root directory, my Nginx installation directory is C: ginx-0.8.53.
Install and configure PHP
I use php5.2. You can use php5.3 or php5.3 to support fastcgi (php-cgi.exe). For the PHP installation and configuration tutorial, refer to: install and configure PHP5 using FastCgi and ISAPI methods in IIS7 Windows 7.
Configure Nginx to support running PHP
First you need to open C: ginx-0.8.53, find the nginx. conf under the C: ginx-0.8.53conf directory, open with notepad,
Step 1 of configuring Nginx to support PHP
Set the directory where error. log is stored. Set the # location of # error_log logs/error. log;. By default, error. log is stored in the logs directory in the Nginx installation directory.
Step 2 of configuring Nginx to support PHP
Set the WEB Server Directory, similar to document_root in the PHP. INI configuration file. The original information in the Nginx configuration file is as follows:
Location /{
Root html;
Index index.html index.htm;
}
Modify the Nginx configuration as follows:
Location /{
Root D:/PHPWeb;
Index. php index.html index.htm;
}
Note that the path separator must be "/" instead of "in Windows" to avoid ambiguity.
Step 3 of configuring Nginx to support PHP
In the Nginx configuration file, find
# Location ~ . Php $ {
# Root html;
# Fastcgi_pass 127.0.0.1: 9000;
# Fastcgi_index index. php;
# Fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name;
# Include fastcgi_params;
#}
Go to # and add the WEB directory, that is
Location ~ . Php $ {
Root D:/PHPWeb;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME D:/PHPWeb $ fastcgi_script_name;
Include fastcgi_params;
}
Note that
Fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name;
Modify/scripts to the previously set WEB directory. Otherwise, an HTTP 404 error will be reported.
Step 3 of configuring Nginx to support PHP
Modify cgi. fix_pathinfo = 1 in the PHP. INI configuration file. PHP will modify SCRIPT_FILENAME to the actual file address. Otherwise, PHP will not be able to find the PHP file to be processed.
So far, Nginx supports the basic configuration of running PHP.
Next, we need to start the PHP FastCgi and Nginx services to run the PHP program. The method is as follows:
1. First download runhiddenconsole.exe
2. Start PHP FastCgi and input it in CMD mode.
RunHiddenConsole C:/php52iis/php-cgi.exe-B 127.0.0.1: 9000-c C:/windows/php. ini
Pay attention to your PHP installation directory and the location of the php. ini configuration file.
3. Start the Nginx service, that is, enter
C:/nginx-0.8.53/nginx.exe
Now Nginx is configured in Windows to support the basic configuration method for running PHP. You can use the phpinfo function to check that the WEB server running PHP has changed to Nginx.