Install and configure Nginx + PHP5 on Windows

Source: Internet
Author: User
Install and configure Nginx and PHP5 in Windows. first, download the latest PHP5.3Windows version from windows. php. netdownload. here PHP runs in FastCGI mode, so please download the NoneTheadSafe version. Decompress the package to C: php5 and install and configure Nginx + PHP5 in php. ini-r Windows.
Install PHP5

First, download the latest PHP 5.3 Windows version from the http://windows.php.net/download/, where PHP runs in FastCGI mode, so please download the None Thead Safe version.

Decompress the package to C: \ php5, change the name of php. ini-recommended in the compressed package to php. ini, and then enable the following options:

1234567891011
Error_reporting = E_ALLdisplay_errors = Onextension_dir = "C: \ php5 \ ext "?; Dynamic expansion, you can remove the comments before extension as needed; for example, load PDO, MySQLextension = php_pdo.dllextension = php_pdo_mysql.dll ?; CGI settings cgi. fix_pathinfo = 1

?

Pay attention to dependencies when loading extensions in PHP. for example, php_exif.dll requires php_mbstring.dll. you must put php_mbstring.dll in front of php_exif.dll to load it successfully. Some extensions depend on additional dll files, such as PHP 5.0 + and php_mysqli.dll depend on libmysql. dll, while php_oci8.dll requires you to install the Oracle 8 client. If you are not familiar with these dependencies, refer to the install.txt file in the installation package.

Search sequence of dependent files: first, the directory where php.exe is located. if it is in ISAPI mode, the startup location of the Web Server will be searched, such as the bin directory of Apache; the second is the directory in the Windows PATH environment variable. HereNoCopy any file to the Windows directory. if necessary, add C: \ php5 to the PATH to facilitate PHP upgrade in the future.

Install Nginx

Starting from v0.7.52, Nginx has been released for Windows. you can download it from its official website:
Http://nginx.net

If you need an earlier version of Nginx for Windows, you can find it on Kevin Worthington's website.

I used 0.8.29. after downloading it, decompress and release the file to C: \ nginx.

So how to configure Nginx so that it can work with PHP?

Configure PHP FastCGI

Nginx needs to work with the FastCGI Server to process requests. you can run the PHP FastCGI Server in either of the following ways:

1
C:/php5/php-cgi.exe -b 127.0.0.1:9000 -c C:/php5/php.ini

Another way is to use third-party tools such as PHP-FPM and cgi-fcgi. Apparently! It is extremely painful to use these tools in Windows. you may need Cygwin and other things. some people have done so, although I think it is self-seeking.

Next, modify Nginx and forward php requests to the 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: $ document_root refers to your php scripts root directory, which is set as your website root directory. In Windows, you must note the root path. it is best to use "/" as the path separator instead of the default "\" in Windows. otherwise, problems may occur. for example, this path: D: \ public_html \ test does not work. Nginx throws a 500 error because \ t in \ test is parsed as a tab. Of course, you can add a backslash escape, for example, D: \ public_html \ test.

Php. conf configuration file:

123456789101112
# Connect to the local port 9000, the port here is the port opened by the PHP FastCGI Server, # Please be consistent with the port opened by the php-cgi.exe # When Nginx receives the php file request, will be automatically forwarded to PHP FastCGI Serverfastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php ;? # Nginx does not support CGI PATH_INFO by default, and the value of SCRIPT_NAME is not standard (combined with PATH_INFO) # The following two lines of commands can be stripped from SCRIPT_NAME to PATH_INFOfastcgi_split_path_info ^ (. + \. php )(. *) $; fastcgi_param PATH_INFO $ fastcgi_path_info ;? Include fastcgi_params;

Create an independent php. conf file to save the configuration. it is purely for the sake of streamlining nginx. conf. you can also write it all in the main configuration file.

Modify php. ini and set cgi. fix_pathinfo = 1. this is very important. PHP will correct SCRIPT_FILENAME to the actual file address. otherwise, PHP will not be able to find the php file to be processed.

For some other settings, the master server:

1234567891011121314
# Number of processes enabled 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 # The default 1024 value is not required for local development. change this value to 64 worker_connections 64 ;}

If the default index. php index.html or other homepage files do not exist under a directory, Nginx will throw a 403 ERROR. if you need to list this directory, you can go to http {... }, Add the following command:

123
autoindex on;autoindex_exact_size on;autoindex_localtime on;

OK, integrated

Create start_nginx.bat to start both PHP FastCGI and Nginx:

123456789101112
@ Echo offREM in Windows REM set PHP_FCGI_CHILDREN = 5REM maximum number of requests processed by each process, or set it to the 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 the DOS window. you can download it here.
After start_nginx.bat is enabled, there will also be a DOS window, but it can be safely disabled, and does not close Nginx and php-cgi.exe.

Similarly, stop_nginx.bat is used to disable:

123456
@echo offecho Stopping nginx...taskkill /F /IM nginx.exe > nulecho Stopping PHP FastCGI...taskkill /F /IM php-cgi.exe > nulexit

The basic configuration is complete.

1 floor vb2005xu 2012-08-09

Http://www.phpvim.net/web/php/build-php5-4-and-xdebug-on-win32.html

2 floor vb2005xu 2012-08-14

Http://www.phpvim.net/web/php/script-for-php-buildin-fcgi-server.html

3 Floor vb2005xu 2012-08-15

Winbinder

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.