Configure nginx+php environment under windows
I just saw the word nginx and I was very curious about its pronunciation (engine x). My literal translation is “engine "Extra effects)", then the whole word means something like "extreme effect", "extra performance". Of course, this is not a chat here, the above is a digression.
The advantage of nginx compared to the familiar apache and IIS, as far as I understand it in a simple way, lies in "reverse proxy" and "load balancing". Therefore, considering the ability to save resources for the web server, it can replace apache to provide web services. So let’s get to the point, nginx has so many advantages, so how to configure the nginx+php environment under windows? There are still so many articles that are reprinted and reprinted online. Here is my configuration process:
1. The application package needs to be prepared first.
nginx: nginx/Windows-1.0.4
php: php-5.2.16-nts-Win32-VC6-x86.zip (php under nginx runs in FastCGI, so we download the non-thread-safe php package of nts)
(Will also be used) RunHiddenConsole: RunHiddenConsole.zip
2. Installation and configuration.
1) Installation and configuration of php.
Directly decompress the downloaded php package and go to the wnmp directory on drive D (D:wnmp). Here, rename the decompressed folder to php5. Enter the folder and modify the php.ini-recommended file to php.ini, and open it with Editplus or Notepad++. Found
extension_dir = "./ext"
changed to
extension_dir = "D:/wnmp/php5/ext"
;extension=php_mysql.dll<br>;extension=php_mysqli.dll
After specifying the ext path of php earlier, just remove the corresponding ";" in front of the required expansion package. Open php_mysql.dll and php_mysqli.dll here to let php support mysql. Of course, don't forget that a very important step is to copy the libmysql.dll file in the php5 directory to the C:Windows directory. You can also specify the path in the system variable. Of course, I chose the more convenient method here^_^.
At this point, php can already support mysql.
Next we will configure php so that php can be combined with nginx. Found
;cgi.fix_pathinfo=1
Let’s remove the ban here.
cgi.fix_pathinfo=1
2) Installation and configuration of nginx.
Extract the downloaded nginx-1.0.4 package to the wnmp directory of the D drive and rename it to nginx. Next, we configure nginx so that it can work with php. Enter the nginx conf directory, open the nginx configuration file nginx.conf, and find
location / {<br> root html; #這里是站點(diǎn)的根目錄<br> index index ?index.html index.htm index.php;<br>}
Change root html; to root D:/wnmp/www;
Go further down and find
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000<br>#<br>#location ~ \.php$ {<br># root html;<br># fastcgi_pass 127.0.0.1:9000;<br># fastcgi_index index.php;<br># fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;<br># include fastcgi_params;<br>#}
First remove the "#" in front, and also change root html; to root D:/wnmp/www;. Then change the /scripts marked in red to "$document_root". The "$document_root" here refers to the site path pointed to by "root". This is after the change:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000<br>#<br>location ~ \.php$ {<br> root D:/wnmp/www;<br> fastcgi_pass 127.0.0.1:9000;<br> fastcgi_index index.php;<br> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br> include fastcgi_params;<br>}
Save the configuration file and that’s it.
The nginx+php environment has been initially configured, let’s take a look. We can enter the command
To start php and start nginx manually, of course, you can also use a script to achieve this.
First, unzip the downloaded RunHiddenConsole.zip package into the nginx directory. The function of RunHiddenConsole.exe is to automatically close the script after executing the command line script, and the process started from the script will not be closed. Then create a script and name it "start_nginx.bat". Let's edit it in Notepad++
@echo off<br>REM Windows 下無效<br>REM set PHP_FCGI_CHILDREN=5<br><br>REM 每個(gè)進(jìn)程處理的最大請(qǐng)求數(shù),或設(shè)置為 Windows 環(huán)境變量<br>set PHP_FCGI_MAX_REQUESTS=1000<br> <br>echo Starting PHP FastCGI...<br>RunHiddenConsole D:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini<br> <br>echo Starting nginx...<br>RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
再另外創(chuàng)建一個(gè)名為stop_nginx.bat的腳本用來關(guān)閉nginx
@echo off<br>echo Stopping nginx...??<br>taskkill /F /IM nginx.exe > nul<br>echo Stopping PHP FastCGI...<br>taskkill /F /IM php-cgi.exe > nul<br>exit
做好后,是這樣的
這樣,我們的服務(wù)腳本也都創(chuàng)建完畢了。雙擊start_nginx.bat看看進(jìn)程管理器是不是有兩個(gè)nginx.exe的進(jìn)程和一個(gè)php-cgi.exe的進(jìn)程呢?
這樣nginx服務(wù)就啟動(dòng)了,而且php也以fastCGI的方式運(yùn)行了。
到站點(diǎn)目錄下,新建一個(gè)phpinfo.php的文件,在里面編輯
<?php <br /> phpinfo();<br>?>
保存后,打開瀏覽器輸入“http://localhost/phpinfo.php”,如果看到
就說明,nginx+php的環(huán)境已經(jīng)配置好了,呵呵~
轉(zhuǎn)自http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)