首頁 > php教程 > php手册 > Windows下安裝Nginx+php+mysql環境

Windows下安裝Nginx+php+mysql環境

WBOY
發布: 2016-09-29 09:19:03
原創
1914 人瀏覽過

系統:Windows 7 64位元系統

安裝前,先下載軟體:

Nginx: http://nginx.org/en/download.html

PHP Stable PHP 5.6.26: http://php.net/downloads.php

mysql: http://dev.mysql.com/downloads/utilities/

 

第一步:在D盤建立資料夾Nginx+php+Mysql,路徑為:D:Nginx+php+Mysql

 

第二步:安裝Nginx,安裝目錄為:D:Nginx+php+Mysqlnginx

  1.開啟D:Nginx+php+Mysqlnginx目錄,執行該資料夾下的nginx.exe

  2.測試是否啟動nginx。打開瀏覽器訪問http://localhost 或 http://127.0.0.1,看看是否出現“Welcome to nginx!”,出現的證明已經啟動成功了。

若啟動不成功,查看是否連接埠被佔用。

    安裝PHP,安裝目錄為:D:Nginx+php+Mysqlphp

    安裝mySQL,安裝目錄為: D:Nginx+php+Mysqlmysql

 

第三步:修改Nginx的conf檔:目錄為D:Nginx+php+Mysqlnginxconf

檔案名稱為:nginx.conf 

1. 去掉worker_processes前的#號,開啟一個進程

2. 新增events

3. 設定http->設定server->支援php

<span style="color: #000000;">#user  nobody;
worker_processes  </span><span style="color: #800080;">1</span><span style="color: #000000;">;
#error_log  logs</span>/<span style="color: #000000;">error.log;
#error_log  logs</span>/<span style="color: #000000;">error.log  notice;
#error_log  logs</span>/<span style="color: #000000;">error.log  info;
#pid        logs</span>/<span style="color: #000000;">nginx.pid;
events {
    worker_connections  </span><span style="color: #800080;">1024</span><span style="color: #000000;">;
}
http {
    include       mime.types;
    default_type  application</span>/octet-<span style="color: #000000;">stream;
    #log_format  main  </span><span style="color: #800000;">'</span><span style="color: #800000;">$remote_addr - $remote_user [$time_local] "$request" </span><span style="color: #800000;">'</span><span style="color: #000000;">
    #                  </span><span style="color: #800000;">'</span><span style="color: #800000;">$status $body_bytes_sent "$http_referer" </span><span style="color: #800000;">'</span><span style="color: #000000;">
    #                  </span><span style="color: #800000;">'</span><span style="color: #800000;">"$http_user_agent" "$http_x_forwarded_for"</span><span style="color: #800000;">'</span><span style="color: #000000;">;
    #access_log  logs</span>/<span style="color: #000000;">access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  </span><span style="color: #800080;">0</span><span style="color: #000000;">;
    keepalive_timeout  </span><span style="color: #800080;">65</span><span style="color: #000000;">;
    #gzip  on;
    server {
        listen       </span><span style="color: #800080;">80</span><span style="color: #000000;">;
        server_name  localhost;
        #charset koi8</span>-<span style="color: #000000;">r;
        #access_log  logs</span>/<span style="color: #000000;">host.access.log  main;
        location </span>/<span style="color: #000000;"> {
            root d:</span>/Nginx+php+Mysql/nginx/<span style="color: #000000;">html;
            index  index.html index.htm;
        }</span><span style="color: #000000;">
        error_page   </span><span style="color: #800080;">500</span> <span style="color: #800080;">502</span> <span style="color: #800080;">503</span> <span style="color: #800080;">504</span>  /<span style="color: #000000;">50x.html;
        location </span>= /<span style="color: #000000;">50x.html {
            root   html;
        }</span><span style="color: #000000;">
        # pass the PHP scripts to FastCGI server listening on </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;">
        #
        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    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }</span><span style="color: #000000;">
    }
}</span>
登入後複製

  測試nginx是否安裝成功

第四步:修改php下php.ini-development文件,將檔名修改為php.ini,找開php.ini:

  搜尋“extension_dir”,找到extension_dir = "ext" 先去前面的分號再改為 extension_dir = "./ext"

   搜尋“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll  去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll SQL

  查看php是否安裝成功:

第四步:在php目錄下新檔案php-cgi.vbs,用php-cgi.vbs檔案啟動php-cgi:

打開php-cgi.vbs,寫入啟動編碼:

<span style="color: #0000ff;">set</span> wscriptObj = CreateObject(<span style="color: #800000;">"</span><span style="color: #800000;">Wscript.Shell</span><span style="color: #800000;">"</span><span style="color: #000000;">)
wscriptObj.run </span><span style="color: #800000;">"</span><span style="color: #800000;">php-cgi -b 127.0.0.1:9000</span><span style="color: #800000;">"</span>,<span style="color: #800080;">0</span>
登入後複製
第五步:在D:Nginx+php+Mysql目錄下新啟動項目:runServer.bat與停止項目stopServer.bat

  在啟動項目runServer.bat中輸入:

<span style="color: #000000;">@echo off
echo Starting nginx...
cd </span>%~<span style="color: #000000;">dp0nginx
start </span><span style="color: #800000;">""</span> <span style="color: #800000;">"</span><span style="color: #800000;">./nginx.exe</span><span style="color: #800000;">"</span><span style="color: #000000;">

echo Starting mysql...
net start mysql

echo Starting PHP FastCGI...
cd </span>%~<span style="color: #000000;">dp0PHP
start </span><span style="color: #800000;">""</span> <span style="color: #800000;">"</span><span style="color: #800000;">php-cgi.vbs</span><span style="color: #800000;">"</span><span style="color: #000000;">

pause

Exit</span>
登入後複製
  在停止項中輸入:

<span style="color: #000000;">@echo off
echo Stopping nginx...
taskkill </span>/F /IM nginx.exe ><span style="color: #000000;"> nul
echo Stopping PHP FastCGI...
taskkill </span>/F /IM php-cgi.exe ><span style="color: #000000;"> nul
echo Stopping mysql...
net stop mysql
pause
exit</span>
登入後複製
最後,查看是否啟動成功:

  在nginx的html目錄下D:Nginx+php+Mysqlnginxhtml,新phpinfo.php

寫入:

<?<span style="color: #000000;">php
phpinfo();
</span>?> 
登入後複製
在瀏覽器中輸入phpinfo.php的路徑,查看是否配置成功:

 

 

 

 

    

 

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板