Configuring nginx+php under Windows

Source: Internet
Author: User
Tags phpinfo

[Turn] http://www.cnblogs.com/fengyuqing/p/php_nginx.html

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

Extension_dir = "./ext"

Change to

Extension_dir = "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

Remove the semicolon inside

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; #这里是站点的根目录      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;#    include        fastcgi_params;#}

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/www;      Fastcgi_pass   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 the command to start PHP, and manually start Nginx, of course, can also be implemented using scripts.

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 The maximum number of requests processed per process, or set to Windows environment variables set php_fcgi_max_requests=1000 echo Starting PHP FastCGI ... Runhiddenconsole d:/wnmp/php5/php-cgi.exe-b 127.0.0.1:9000-c d:/wnmp/php5/php.ini echo 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  ... taskkill/f/im nginx.exe > Nulecho stopping PHP fastcgi...taskkill/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

<?php    phpinfo ();? >

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

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

Configuring nginx+php under Windows

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.