Installation and configuration of Windows Nginx + PHP5
Installing PHP5
First, download the latest version of PHP 5.3 windows from http://windows.php.net/download/, where PHP runs in FastCGI mode, so please download the None Thead Safe version.
Unzip to C:\PHP5, rename the php.ini-recommended in the package to php.ini, and then open the Modify several options:
1234567891011 |
error_reporting =E_alldisplay_errors = onExtension_dir = "C:\php5\ext"?dynamic expansion, you can remove the extension in front of the comments as needed;, such as loading PDO, MySQLextension=Php_pdo.dllextension=Php_pdo_mysql.dll?; CGI SettingsCgi.fix_pathinfo=1 |
?
PHP load extensions need to be aware of dependencies, such as Php_exif.dll needs Php_mbstring.dll, you have to put Php_mbstring.dll in front of the Php_exif.dll to load successfully. Some extensions rely on additional DLL files, such as PHP 5.0+, Php_mysqli.dll relies on Libmysql.dll, and Php_oci8.dll, you need to install Oracle 8 client. If you are not familiar with these dependencies, refer to the Install.txt file in the installation package.
The search order of dependent files: First is the directory where the Php.exe is located, if it is ISAPI mode, the startup location of the Web Server is searched, such as the Apache bin directory, followed by the directory in the Windows PATH environment variable. do not copy any files to the Windows directory, if necessary, you can add C:\PHP5 to PATH, convenient for later PHP upgrade.
Installing Nginx
Starting with v0.7.52, Nginx launches the Windows version of Nginx, which you can download on its official website:
Http://nginx.net
If you need an older version of Nginx for Windows, you can find it on Kevin Worthington's website.
I am using 0.8.29, download good later, unzip release file to C:\nginx.
So how can I configure Nginx so that it works in conjunction with PHP?
Configure PHP FastCGI
Nginx needs to work with FastCGI server in order to process requests, there are two ways to run PHP FastCGI server, one is to use PHP built-in FastCGI Manager:
1 |
C:/php5/-b 127.0.0.1:9000 C:/php5/php.ini |
Another way is to use third-party tools, such as PHP-FPM, cgi-fcgi, and so on. Obviously! It's extremely painful to use these tools in Windows, and you might need to Cygwin something like that, and someone did, though I think it was trouble.
Next, modify Nginx to forward the PHP request to PHP FastCGI Server:
123456 |
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ ^ (. +\.php) (. *) $ { root d:/ public_html; Fastcgi_param script_filename $document _root$fastcgi_script_name; include php.conf;} |
Root is $document _root refers to your PHP scripts root directory, which is set to the root directory of your Web site. Under Windows, you need to be aware of the root path, it is best to use "/" as the path delimiter, rather than Windows default "\", otherwise prone to problems, such as this path: D:\public_html\test, will not work, Nginx will 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 configuration file:
123456789101112 |
# Connect to the native 9000 port, where the port refers to the port that PHP FastCGI Server opens, # Please be consistent with Php-cgi.exe open ports # when Nginx receives PHP file request, it is automatically forwarded to PHP FastCGI Serverfastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php;? # Nginx default is not supported CGI Path_info,script_name value is also not standard (PATH_INFO) # The following two lines of instruction can be stripped out of the Script_name path_infofastcgi_split_path_info ^ (. +\.php) (. *) $;fastcgi_param Path_ INFO $fastcgi _path_info;? include Fastcgi_params; |
Create a standalone php.conf save configuration, purely for the sake of streamlining nginx.conf, personal habits, or all in the master configuration file.
Modify PHP.ini, set cgi.fix_pathinfo = 1, which is very important, PHP will fix script_filename as the real file address, otherwise PHP will not be able to find the PHP file to be processed.
Some other settings for the master server:
1234567891011121314 |
# Number of processes open 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 {# Maximum number of connections processed by a process,# Local development, no default 1024, change hereto worker_connections 64 ;} |
When a directory does not exist under the default index.php index.html, such as the home page file, Nginx will throw 403 ERROR, if you need to list this directory, you can add the following command in the HTTP {...}:
OK, integrate together
Create Start_nginx.bat to start PHP FastCGI and Nginx at the same time:
123456789101112 |
@ Echo offrem Windows invalid rem set php_fcgi_children=5rem per process processing maximum number of requests, or set to Windows environment variable set php_fcgi_max_requests=1000? Echo Starting PHP FastCGI ... Runhiddenconsole c:/php5/php-cgi.exe-b 127.0.0.1:9000-c C:/php5/php.ini? Echo Starting Nginx ... C:/nginx/nginx.exe-p C:/nginx |
RunHiddenConsole.exe is a small program used to hide DOS windows, which can be downloaded here.
After the Start_nginx.bat is turned on, there will also be a DOS window, but it can be safely turned off, and will not close Nginx and php-cgi.exe.
Same stop_nginx.bat, used to close:
123456 |
@ echo offecho>nulecho>nulexit |
The basic configuration is complete here.
1/F Vb2005xu 2012-08-09
Http://www.phpvim.net/web/php/build-php5-4-and-xdebug-on-win32.html
2/F Vb2005xu 2012-08-14
Http://www.phpvim.net/web/php/script-for-php-buildin-fcgi-server.html
3/F Vb2005xu 2012-08-15
Winbinder