Rumah  >  Artikel  >  php教程  >  Windows下配置nginx+php(wnmp)

Windows下配置nginx+php(wnmp)

WBOY
WBOYasal
2016-06-10 15:07:111234semak imbas

第一部分:准备工作。(系统:Windows 8.1)

1.首先是下载软件。

NGINX-1.3.8官网下载:http://nginx.org/en/download.html

PHP5.4.8版本下载地址:http://windows.php.net/download/

Mysql5.5.28版本下载地址:http://www.mysql.com/downloads/mysql/

2.安装mysql软件。

 

3.解压NGINX和PHP到你自己安装位置。这里我在C盘新建一个文件夹:wnmp(windows,ngnix,myspq,php),把下面的软件安装到这个文件夹里面。

NGINX目录C:\wnmp\nginx

PHP目录C:\wnmp\php

 

第二部分:安装nginx

1.打开C:\nginx目录,运行该文件夹下的nginx.exe

2.测试是否启动nginx。打开浏览器访问http://localhost 或 http://127.0.0.1,看看是否出现“Welcome to nginx!”,出现的证明已经启动成功了。没有启动的话,看看80端口有占用没。

注意:该网站的默认目录在“C:\wnmp\nginx\htm”l下

 

第三部分:安装php(这里主要讲nginx配置启动php,以cgi运行php)

nginx配置文件是conf文件夹里的nginx.conf

1.修改大概第43~45行之间的

 

            location /<span style="color: #000000;">{
            root   html;
            index  index.html index.htm;}</span>

 

修改网站文件的路径,以及添加index.php的默认页。

        location /<span style="color: #000000;"> {
            root   D:</span>/wnmp/nginx-<span style="color: #800080;">1.5</span>.<span style="color: #800080;">8</span>/<span style="color: #000000;">html;
            index  index.html index.htm inde.php;
        }</span>

 

2.支持php的设置

 

修改大概在第63-71行的

        # pass the PHP scripts to FastCGI server listening on <span style="color: #800080;">127.0</span>.<span style="color: #800080;">0.1</span>:<span style="color: #800080;">9000</span><span style="color: #000000;">
        #
        #location </span>~<span style="color: #000000;"> \.php$ {
        #    root           html;
        #    fastcgi_pass   </span><span style="color: #800080;">127.0</span>.<span style="color: #800080;">0.1</span>:<span style="color: #800080;">9000</span><span style="color: #000000;">;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  </span>/<span style="color: #000000;">scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}</span>

 

先将前面的“#”去掉,同样将root  html;改为root  C:/wnmp/nginx-1.5.8/html;。再把“/scripts”改为“$document_root”,这里的“$document_root”就是指前面“root”所指的站点路径,这是改完后的:

        # pass the PHP scripts to FastCGI server listening on <span style="color: #800080;">127.0</span>.<span style="color: #800080;">0.1</span>:<span style="color: #800080;">9000</span><span style="color: #000000;">
        #
        #location </span>~<span style="color: #000000;"> \.php$ {
        #    root           C:/wnmp/nginx-1.5.8/html;
        #    fastcgi_pass   </span><span style="color: #800080;">127.0</span>.<span style="color: #800080;">0.1</span>:<span style="color: #800080;">9000</span><span style="color: #000000;">;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  $document_root</span><span style="color: #000000;">$fastcgi_script_name;
        #    include        fastcgi_params;
        #}</span>

 

3.C:\wnmp\php\ext下修改php.ini-development文件,将文件名修改为php.ini,打开php配置文件php.ini,保存即可。

搜索“extension_dir”,找到: e;xtension_dir = "ext" 先去前面的分号再改为 extension_dir = "C:\wnmp\php\ext"

搜索“date.timezone”,找到:;date.timezone = 先去前面的分号再改为 date.timezone = Asia/Shanghai

搜索“enable_dl”,找到:enable_dl = Off 改为 enable_dl = On

搜索“cgi.force_redirect” ;cgi.force_redirect = 1 先去前面的分号再改为 cgi.force_redirect = 0

搜索“fastcgi.impersonate”,找到: ;fastcgi.impersonate = 1 去掉前面的分号

搜索“cgi.rfc2616_headers”,找到:;cgi.rfc2616_headers = 0 先去前面的分号再改为 cgi.rfc2616_headers = 1

 

搜索“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll  去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll   (支持MYSQL数据库)

 

其他的配置请按照自己的需求更改。

 

第三部分试运行以及编辑运行配置文件

<span class="pun">C:\wnmp\php-5.5.7-nts-Win32-VC11-x86></span><span class="pln">php</span><span class="pun">-</span><span class="pln">cgi</span><span class="pun">.</span><span class="pln">exe </span><span class="pun">-</span><span class="pln">b </span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">:</span><span class="lit">9000</span><span class="pun">-</span><span class="pln">c C:\wnmp\php-5.5.7-nts-Win32-VC11-x86</span><span class="pln">\php</span><span class="pun">.</span><span class="pln">ini</span>

重新运行nginx.exe。

 

 

C:\wnmp\nginx-1.5.8\html下新建一个phpinfo.php,

<?php <span style="color: #008080;">phpinfo(); ?>

 

访问http://localhost/phpinfo.php

或者http://127.0.0.1/phpinfo.php

出现如下的信息就说明php已经成功安装:

 

下载一个RunHiddenConsole.exe,百度网盘。

开启php-cgi和nginx.exe,保存为start.bat

 

<span style="color: #0000ff;">@echo</span> <span style="color: #0000ff;">off</span>
<span style="color: #0000ff;">echo</span> Starting PHP FastCGI...<span style="color: #000000;">
C:</span>\wnmp\nginx\RunHiddenConsole.exe C:\wnmp\PHP\php-cgi.exe -b 127.0.0.1:9000-c D:\PHP\php.<span style="color: #000000;">ini
</span><span style="color: #0000ff;">echo</span> Starting nginx...<span style="color: #000000;">
C:\wnmp</span>\nginx\RunHiddenConsole.exe D:/nginx/nginx.exe -p D:/nginx

 

 

 

停止php-cgi和nginx.exe,保存为stop.bat

<span style="color: #0000ff;">@echo</span> <span style="color: #0000ff;">off</span>
<span style="color: #0000ff;">echo</span> Stopping nginx...<span style="color: #000000;">
taskkill </span>/F /IM nginx.exe ><span style="color: #000000;"> nul
</span><span style="color: #0000ff;">echo</span> Stopping PHP FastCGI...<span style="color: #000000;">
taskkill </span>/F /IM php-cgi.exe ><span style="color: #000000;"> nul
</span><span style="color: #0000ff;">exit</span>

 

 

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:PHP时间戳与日期之间的转换Artikel seterusnya:php导出csv格式文件