Configuring the nginx+php environment under Windows

Source: Internet
Author: User
Tags phpinfo

Just see the word nginx, I am very curious about its reading (engine x), my literal translation is "engines X", generally cited "xtras" table performance, and "X" mostly appears to mean "the extra effect", then the whole word meaning is similar to "extreme effect", "Extra performance". Of course, this is not to come to chit chat when, above is a digression.

Nginx compared to the advantages of our familiar Apache, IIS, I shallow into the shallow out of the understanding, is "reverse proxy" and "load balancing." So considering the ability to save resources for the Web server, it can provide Web services instead of Apache. So to the point, Nginx has so many advantages, that under Windows How to configure the nginx+php environment? Online to see or so many reproduced to reprint to the article. Here is the process of my configuration, to introduce:

1. First, you need to prepare the application package.

nginx:nginx/windows-1.0.4

Php:php-5.2.16-nts-win32-vc6-x86.zip (Nginx PHP is run in fastcgi mode, so we download non-thread-safe is nts PHP package)

(will also be used) RunHiddenConsole:RunHiddenConsole.zip

2, installation and configuration.

1) Installation and configuration of PHP.

Directly unzip the downloaded PHP package, to the D disk Wnmp directory (D:\WNMP), here the extracted folder renamed to PHP5. Go to Folder to modify the php.ini-recommended file to PHP.ini, and open it with EditPlus or notepad++. Found it

" ./ext "

Change to

" D:/wnmp/php5/ext "

Look down, then find

; extension=php_mysql.dll;extension=php_mysqli.dll

Once you have specified the ext path of PHP, just put the ";" in front of the required expansion pack. get rid of it. Here, open Php_mysql.dll and Php_mysqli.dll, and let PHP support MySQL. Of course, don't forget the important step is to copy the PHP5 directory under the Libmysql.dll file to C:\Windows directory, you can also specify the path in the system variables, of course, I chose a more convenient method ^_^.

Here, PHP is ready to support MySQL.

Next, let's configure PHP so that PHP can be combined with nginx. Found it

; cgi.fix_pathinfo=1

Let's get rid of the semicolon here.

Cgi.fix_pathinfo=1

This step is very important, here is the CGI settings for PHP.

2) Installation and configuration of Nginx.

The downloaded nginx-1.0.4 package is also extracted to the D-disk Wnmp directory, and renamed Nginx. Next, let's configure Nginx to work with PHP. Enter the Nginx conf directory, open the Nginx configuration file nginx.conf, find

Location/ {root HTML;  # Here is the root directory of the site index index.html index.htm;}

The root HTML will be changed to root d:/wnmp/www;

Go down and find

 #   pass the PHP scripts to FastCGI server Listening on 127.0.0.1:9000  ##  location ~ \.php$ { #   root html;  #   Fastcgi_pass 127.0.0.1:9000;  #   Fastcgi_index index.php;  #   Fastcgi_param Script_filename/scripts$fastcgi_script_name;  #   #    

First the "#" is removed, the same root HTML, to root d:/wnmp/www;. Then the marked red/scripts changed to "$document _root", where the "$document _root" refers to the previous "root" refers to the site path, this is changed:

# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #Location ~ \.php$ {root D:/wnmp/127.0.0.1:9000; Fastcgi_index index.php;fastcgi_ param script_filename $document _root$fastcgi_script_name;include fastcgi_params;}

Save the configuration file and you're ready.

Nginx+php the environment is initially configured, to run to see. We can enter a command

To start PHP, and manually start Nginx, of course, you can also use the script to implement.

First, the downloaded Runhiddenconsole.zip package is extracted into the Nginx directory, the role of RunHiddenConsole.exe is to automatically close the script after executing the command line script, and the process opened from the script is not closed. Then create the script, named "Start_nginx.bat," and we'll edit it in notepad++.

@echo offrem windows under invalid REM set Php_fcgi_children=5rem per process the maximum number of requests processed, or set to Windows environment variable set php_fcgi_max_ Requests=1000Echo starting PHP FastCGI ... Runhiddenconsole D:/wnmp/php5/php-cgi.exe-b 127.0.0.1:9000-c d:/wnmp/php5/php.iniecho Starting nginx ... Runhiddenconsole D:/wnmp/nginx/nginx.exe-p D:/wnmp/nginx

Create another script named Stop_nginx.bat to close Nginx

@echo Offecho stopping nginx   ... /f/im nginx.exe >/f/im php-cgi.exe > nulexit

After doing it, it's like this.

In this way, our service scripts have been created. Double-click Start_nginx.bat to see if the process manager has two nginx.exe processes and a php-cgi.exe process?

This will start the Nginx service, and PHP will run in a fastcgi manner.

To the Site directory, create a new phpinfo.php file, edit it inside

<phpphpinfo ();? >

After saving, open the browser input "http://localhost/phpinfo.php", if you see

It shows that the nginx+php environment has been configured, hehe ~

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.