Development environment of building nginx+php under Win7

Source: Internet
Author: User

The use of IIS as a Web server in Win7, but recently because of the project requirements, the server encountered a 404 error when the auto-turn (not in the client's jump, but the server received a client request to go to a directory to read the file return, if the directory or directory is found that the file does not exist, Automatically go to another server to fetch), with IIS found it difficult to do this, so decided to build the Nginx development environment, through configuration to achieve this.

First, Google Nginx and PHP, respectively, to their official website to the latest version of the download back, I was under the PHP is 5.4.3 version, Nginx is 1.5.2, I put them in the D disk under a Webserver folder, and then began to do configuration.

Nginx startup is very simple, enter its directory, and then double-click Nginx.exe, if there is no port conflict, and so on, directly in the browser input localhost can access the Welcome to Nginx page, which is the default welcome page, Placed under the Default Web page file directory HTML that comes with it. Is it that simple? Of course not.

At this point if you build a PHP file in the HTML directory, write a sentence to test the PHP environment of the most classic, and then in the browser input the path of the PHP file to access, you will find Nginx does not understand how to parse the PHP code, this is because Nginx and PHP have not cooperated. As a result, when the PHP file is encountered, Nginx should give it to PHP fast-cgi to handle, and then return the processed results to the client (browser).

How do I tell Nginx who will handle the PHP file when it is encountered? Open the nginx1.5.2 folder, locate the Conf directory, edit the nginx.conf file in the directory, and the results of my edits are as follows, as shown in the specific configuration process, see the Note:

server {

Listen 80;

server_name localhost;

CharSet Utf-8;

Location/{

Root e:/work/jentian/client;//html file directory, because our project's client code and service-side services are strictly separate, so here root is different from PHP root

Index index.html index.htm;

}

Location ~. php {

Root E:/work/jentian/server; PHP file directory

Fastcgi_param script_filename e:/work/jentian/server$fastcgi_script_name;//Note, $fastcgi _script_ The path in front of name must be the same as root

Fastcgi_index index.php;

Fastcgi_pass 127.0.0.1:9000;

Include Fastcgi_params;

}

}

Nginx configuration is so much, very simple, but this time when you refresh the PHP page, you will find Nginx still have no way to parse php file, because PHP fast-cgi has not started, if you open a normal command prompt window, Then enter the command to start fast-cgi, after the start of this window can not be closed, or the fast-cgi process will also be terminated, can not continue to parse PHP files, and later checked, the original Windows is a way to run the stealth console, using this method to start fast-cgi , it is not afraid to close the console after the fast-cgi also followed the end of the problem. Finally, write a batch file to start fast-cgi and Nginx, this can be a button to start the nginx+php environment. Here is the contents of this batch file:

@echo off

Set php_fcgi_max_requests = 1000

echo Starting PHP FastCGI ...

REM below here is replaced by your php-cgi.exe and php.ini path, the following-b,-c parameters must be preserved and note the front and rear spaces

Runhiddenconsole d:/webserver/php-5.4.3/php-cgi.exe-b 127.0.0.1:9000-c D:/webserver/php-5.4.3/php.ini//Here

Echo Starting Nginx ...

REM note replaced with your Nginx directory

D:/webserver/nginx-1.5.2/nginx.exe-p d:/webserver/nginx-1.5.2/

CD D:/WEBSERVER/NGINX-1.5.2/

Pause

Save this batch file to a good, double-click, you can start your nginx+php environment, then refresh your phpinfo page, everything is normal.

Development environment of building nginx+php under Win7 (turn)

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.