Installation and configuration method of nginx+php5 under Windows _nginx

Source: Internet
Author: User
Tags php script
Here are the steps I Nginx and PHP5.2 in Windows 2003 installation, but the Nginx performance of Windows version is much worse than the Linux/uninx version of Nginx

Install PHP5
First, download the latest version of Php5.2.9-2 Windows from http://www.php.net/downloads.php, extract it to C:\php, and rename the php.ini-recommended in the compressed package to PHP.ini, and then turn on modifying several options:

error_reporting = E_all
Display_errors = On
Extension_dir = "C:\php\ext"

; Dynamic expansion, you can remove the extension before the annotation as needed;
; such as loading PDO, MySQL
Extension=php_pdo.dll
Extension=php_pdo_mysql.dll

; CGI settings
Cgi.force_redirect = 1
Cgi.fix_pathinfo = 1
Cgi.rfc2616_headers = 1

PHP load extensions need to pay attention to dependencies, such as Php_exif.dll need Php_mbstring.dll, you have to put Php_mbstring.dll in front of Php_exif.dll to load successfully. Some extensions rely on additional DLL files, such as PHP 5.0+, Php_mysqli.dll rely on Libmysql.dll, and Php_oci8.dll, you need to install Oracle 8 clients. If you are not too familiar with these dependencies, refer to the Install.txt file in the installation package.

Search order for dependent files: first, the directory where Php.exe resides, and if it is ISAPI mode, search the startup location of the Web Server, such as the Apache bin directory, followed by the directory in the Windows PATH environment variable. Do not copy any files here to the Windows directory, if necessary, you can add C:\php5 to the PATH, in favor of the later PHP upgrade.

Install Nginx
Starting with v0.7.52, Nginx started publishing the Windows version of Nginx, which you can download on its official website: http://nginx.net
I am using 0.8.37, after downloading good, decompression release file to D:\nginx.

Configure PHP FastCGI
Nginx need to work with FastCGI server to handle requests, there are two ways to run PHP FastCGI server, one is to use the PHP built-in FastCGI manager:
Execute c:/php/php-cgi.exe-b 127.0.0.1:9000-c c:/php/php.ini below the command line to start PHP FastCGI

Modify the Nginx profile d\nginx\conf\nginx.conf, locate the PHP-related section, and modify the following:
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
Location ~ \.php$ {
Root d:/public_html;
Include php.conf;
}
Root is $document _root refers to your PHP scripts root directory, set to your site root directory. Under Windows, you need to be aware of the root path, preferably using "/" as the path separator, rather than Windows default "\", otherwise prone to problems, such as the path: D:\public_html\test, will not work, Nginx would throw 500 Error, because \ t is parsed as a tab in \test. Of course, plus a backslash escape is also possible, such as: D:\\public_html\\test.

Php.conf is the file I created myself to save the PHP configuration, with only 3 lines in it:
# Connect to the native 9000 port, where the port refers to the port on which the PHP FastCGI Server is opened,
# Please keep in line with the ports opened by Php-cgi.exe
# when Nginx receives a request for a PHP file, it is automatically forwarded to the PHP FastCGI Server
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include Fastcgi_params;
To create a separate php.conf save configuration to streamline nginx.conf, when you configure multiple virtual hosts in Nginx, each virtual host needs to configure PHP, and the primary configuration file becomes redundant and bloated.

You need to modify the d:\nginx\conf\fastcgi_params file and join a line:
Fastcgi_param script_filename $document _root$fastcgi_script_name;

and to modify php.ini, set cgi.fix_pathinfo = 1, which is very important, otherwise PHP will not be able to find the PHP script that needs to be processed.

Some other settings, master server:
# Number of processes opened by default
Worker_processes 1;
Error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
#pid Logs/nginx.pid;
Events {
# The maximum number of connections processed by a process,
# Local development, do not need the default 1024, this is changed to 64
Worker_connections 64;
}

When a directory does not exist under the default index.php index.html and other home files, Nginx will throw 403 ERROR, if you need to list this directory, you can add the following command in HTTP {...}:
autoindex on;
Autoindex_exact_size on;
Autoindex_localtime on;
 
Start_nginx.bat , which is used to start both PHP FastCGI and nginx:
@echo off
Echo starting PHP FastCGI ...
Runhiddenconsole c:/php/php-cgi.exe-b 127.0.0.1:9000-c C:/php/php.ini
Echo starting nginx ... The
D:/nginx/nginx.exe
RunHiddenConsole.exe is a small program to hide the DOS window, where you can download Runhiddenconsole.zip (1.01 kb). The
Start_nginx.bat will have a DOS window when it is turned on, but it can be safely turned off and will not close Nginx and php-cgi.exe.
Stop_nginx.bat , used to close:
@echo off
Echo stopping nginx ...
taskkill/f/im nginx.exe > Nul
echo stopping PHP FastCGI ...
taskkill/f/im php-cgi.exe > nul
Exit
Here is the basic configuration complete.

If you feel more trouble, here is recommended for everyone software Phpfind, after installation for the Windows system configured well nginx+php.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.