The development environment of nginx+php under Win7

Source: Internet
Author: User
Tags ini php file php code phpinfo

IIS is used as a Web server under Win7, but recently because of the requirements of the project, it is necessary to automatically make a turn when the server encounters a 404 error (not on the client's jump, but when the server receives the client request to read the file back in a directory, if the file does not exist in the directory or directory, Automatically go to another server to fetch), found it difficult to do this with IIS, and decided to build a nginx development environment, through configuration to achieve this.

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

Nginx start 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 welcome to nginx the words of the page, this is the default welcome page, Placed under the Default Web page file directory HTML. Is it that simple? Of course not.

Then if you build a PHP file in the HTML directory, write a test of the most classic PHP environment , and then in the browser to enter the path of the PHP file access, you will find nginx do not know how to parse the PHP code, This is because Nginx and PHP have not yet cooperated. In principle, when the PHP file is encountered, Nginx should give it to the PHP fast-cgi to handle, and then return the processing results to the client (browser).

How to tell Nginx when you encounter PHP files to whom to deal with? Open the nginx1.5.2 folder, find the Conf directory, edit the nginx.conf file in the directory, my editing results are as follows, the specific configuration process needs to look at 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 this root is different from the 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;//attention, $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 that Nginx now still have no way to parse the PHP file, because the 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 the window can not be closed, otherwise the fast-cgi process will terminate, can not continue to parse the PHP file, then 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 by the end of the problem. Finally, a batch file is written to start fast-cgi and Nginx, which can start the nginx+php environment in one click. The following are the contents of this batch file:

@echo off

Set php_fcgi_max_requests = 1000

echo Starting PHP FastCGI ...

REM Here is replaced by the path of your php-cgi.exe and php.ini, followed by the-b,-c and other parameters must be retained and note the space before and after

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, all normal.

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.