Install and configure Nginx + PHP on Windows

Source: Internet
Author: User
Installation and configuration of Nginx + PHP in Windows & lt ;! -- [If! SupportLists] -- & gt ;? 1. & lt ;! -- [Endif] -- & gt; software preparation & lt ;! -- [If! SupportLists] -- & gt; 1. & lt ;! -- [Endif] -- & gt; Nginx: installation and configuration of nginx + PHP in Nginx. orgdownloadnginx Windows

? I. Software preparation

1. Nginx: http://nginx.org/download/nginx-1.2.0.zip

2. Php: http://windows.php.net/download/php-5.2.17-Win32-VC6-x86.zip here need to pay attention to, if you use Apache or Nginx to run php, to select the thread-safe version of VC6, use IIS to select VC9 version. So the former is used here.

3. RunHiddenConsole: the http://redmine.lighttpd.net/attachments/660/RunHiddenConsole.zip is used to hide the command window.

II. install Php

First, extract the downloaded PHP file to the php installation directory PHP_PATH, and add PHP_PATH and PHP_PATH/ext to the Path environment variable.

Rename php. ini-dist under PHP_PATH to php. ini, which is the configuration file of PHP. Modify the file as needed.

3. install Nginx

Decompress the downloaded nginx-1.2.0.zip and name its folder as a nginx-1.2 ?, You can start nginx through command line or script. The following describes the script method.

Create a start_nginx.bat and a stop_nginx.bat file respectively and place them in the nginx root directory.

The start_nginx.bat content is as follows:

@ Echo off

Echo Starting nginx...

D:/nginx1.2/nginx.exe

The content of stop_nginx.bat is as follows:

@ Echo off

Echo Stopping nginx...

Taskkill/F/IM nginx.exe> nul

Exit

Start nginx. if the welcome page of nginx appears, nginx is successfully installed.

IV. Nginx and PHP configuration

1. in windows, Nginx goes through fast-cgiand PHP. this is based on php-cgi.exe and needs to be executed through commands. the format is as follows:

Php-cgi.exe-B 127.0.0.1:

In this example, php-cgi.exe can listen to client connection requests, but this opens a command line window. You can use the runhiddenconsoletool to hide this window, decompress runhiddenconsole.zip, and copy runhiddenconsole.exe to the nginx root directory.

2. add the script for starting and stopping php-cgi.exe to the start_nginx.bat and stop_nginx.bat files (in blue ):

The start_nginx.bat content is as follows:

?

@ Echo off

Echo Starting PHP FastCGI...

RunHiddenConsole D:/PHP5.2.17/php-cgi.exe-B 127.0.0.1: 9000-c D:/PHP5.2.17/php. ini

Echo Starting nginx...

D:/nginx1.2/nginx.exe

?

The content of stop_nginx.bat is as follows:

?

@ Echo off

Echo Stopping nginx...

Taskkill/F/IM nginx.exe> nul

Echo Stopping PHP FastCGI...

Taskkill/F/IM php-cgi.exe> nul

Exit

3. modify the nginx configuration file nginx. conf.

First, modify the port number as needed. in line 36, modify the listen? ? ? 80; for listen? ? ? 8012; (any modification allowed)

Then, add the support for searching the index. php file by default in row 45 and modify the index? Index.html index.htm; index? Index. php index.html index.htm;

Finally, 65 rows to 71 rows are modified.

The original code is:

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;

? ? ? ? }

To:

Location ~ \. Php $ {

? ? ? ? ? #? Root? ? ? ? ? Html;

? ? ? ? ? ? Fastcgi_pass? 127.0.0.1: 9000;

? ? ? ? ? ? Fastcgi_index? Index. php;

? ? ? ? ? ? Fastcgi_param? SCRIPT_FILENAME? D:/nginx1.2/html $ fastcgi_script_name;

? ? ? ? ? ? Include? ? ? ? Fastcgi_params;

? ? ? ? }

The blue font must be changed to the directory where your php file is located.

5. double-click start_nginx.bat to start nginx and php

Enter http: // localhost: 8012/index. php in the browser. if the welcome page of php appears, nginx and php are successfully configured.

?

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.