Configuring the nginx+php environment under Windows
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
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
We'll get rid of the number 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; #这里是站点的根目录
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 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 off
Inactive under REM Windows
REM Set php_fcgi_children=5
REM maximum number of requests processed per process, or set to Windows environment variable
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 off
echo Stopping Nginx ...
taskkill/f/im nginx.exe > nul
echo Stopping PHP FastCGI ...
taskkill/f/im php-cgi.exe > nul
Exit
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 ~