Table of Contents
Configure nginx+php environment under windows
Home php教程 php手册 wnmp environment setup

wnmp environment setup

Sep 24, 2016 am 09:02 AM

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"
Copy after login

changed to

extension_dir = "D:/wnmp/php5/ext"
Copy after login
Look down and find
;extension=php_mysql.dll<br>;extension=php_mysqli.dll
Copy after login

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
Copy after login

Let’s remove the ban here.

cgi.fix_pathinfo=1
Copy after login
This step is very important. Here are the CGI settings for php.

 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;      #这里是站点的根目录<br>      index  index  index.html index.htm index.php;<br>}
Copy after login

Change root html; to root D:/wnmp/www;

Go further down and find

wnmp environment setup
# 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>#}
Copy after login
wnmp environment setup

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:

wnmp environment setup
# 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>}
Copy after login
wnmp environment setup

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++

wnmp environment setup
@echo off<br>REM Windows 下无效<br>REM set PHP_FCGI_CHILDREN=5<br><br>REM 每个进程处理的最大请求数,或设置为 Windows 环境变量<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
Copy after login
wnmp environment setup

再另外创建一个名为stop_nginx.bat的脚本用来关闭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
Copy after login

做好后,是这样的

这样,我们的服务脚本也都创建完毕了。双击start_nginx.bat看看进程管理器是不是有两个nginx.exe的进程和一个php-cgi.exe的进程呢?

这样nginx服务就启动了,而且php也以fastCGI的方式运行了。

到站点目录下,新建一个phpinfo.php的文件,在里面编辑

<?php <br />    phpinfo();<br>?>
Copy after login

保存后,打开浏览器输入“http://localhost/phpinfo.php”,如果看到

就说明,nginx+php的环境已经配置好了,呵呵~

转自http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)