Home  >  Article  >  php教程  >  wnmp environment setup

wnmp environment setup

WBOY
WBOYOriginal
2016-09-24 09:02:471578browse

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"
Look down and find
;extension=php_mysql.dll
;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
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 / {
root html;      #这里是站点的根目录
index index  index.html index.htm index.php;
}

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
#
#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;
#}
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
#
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;
}
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
REM Windows 下无效
REM set PHP_FCGI_CHILDREN=5

REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
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
wnmp environment setup

再另外创建一个名为stop_nginx.bat的脚本用来关闭nginx

@echo off
echo Stopping nginx...  
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit

做好后,是这样的

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

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

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

    phpinfo();
?>

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

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

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

Statement:
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