win7下搭建nginx+php的開發環境_win伺服器

來源:互聯網
上載者:User

一、下載相關軟體

nginx下載:http://nginx.org/en/download.html

nginx常見異常:http://feiger.cn/?p=2719

php下載:http://windows.php.net/download#php-7.0

下載RunHiddenConsole:http://www.xdowns.com/soft/1/71/2012/Soft_89261.html

二、配置

nginx.conf檔案,我的編輯結果如下所示,具體配置過程中需要注意什麼請看注釋:

  server {

  listen 80;

  server_name localhost;

  charset utf-8;

        location / {

                       root D:\work\soft\php\www;#網站目錄

index index.html index.php;#加上對php的支援

autoindex on;#如果檔案不存在列出目錄結構;

                }

location ~ \.php$ {

root D:\work\soft\php\www;

fastcgi_param SCRIPT_FILENAME D:\work\soft\php\www$fastcgi_script_name;

fastcgi_index index.php;

fastcgi_pass 127.0.0.1:9000;

include fastcgi_params;

}

    }

php配置:

指定docroot——php檔案的存放目錄,即你的documentroot。doc_root = “F:/WAMP/www”
擴充存放目錄 extension_dir——更改為真實的擴充存放地址。extension_dir = “./ext”
預設時區更改——在[Date]裡面增加:date.timezone = Asia/ChongQing
因為nginx需要的是cgi方式的php,所以如下幾個地方是重點,否則nginx無法開啟php檔案:
enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1

三、編輯 php與nginx啟動指令碼:

@echo off  
set root= %~dp0
set php_home=%root%../../php-7.0.6-Win32-VC14-x86
set nginx_home=%root%

REM Windows 下無效  
REM set PHP_FCGI_CHILDREN=5  

REM 每個進程處理的最大請求數,或設定為 Windows 環境變數  
set PHP_FCGI_MAX_REQUESTS=1000  

echo Starting PHP FastCGI...  %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini  
RunHiddenConsole %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini  

echo Starting nginx...  %nginx_home%/nginx.exe
RunHiddenConsole %nginx_home%/nginx.exe  

如果運行過程中報:無法啟動此程式,因為電腦中丟失VCRUNTIME140.dll 嘗試重新安裝此程式以解決此問題

32位版下載地址:http://download.microsoft.com/download/9/E/1/9E1FA77A-9E95-4F3D-8BE1-4D2D0C947BA2/enu_INREL/vcredistd14x86/vc_redist.x86.exe

http://www.microsoft.com/en-us/download/details.aspx?id=46881

64位版下載地址:http://download.microsoft.com/download/9/E/1/9E1FA77A-9E95-4F3D-8BE1-4D2D0C947BA2/enu_INREL/vcredistd14x64/vc_redist.x64.exe

 

四、編輯 php與nginx停止指令碼:

@echo off  

echo Stopping nginx...    

taskkill /F /IM nginx.exe > nul  

echo Stopping PHP FastCGI...  

taskkill /F /IM php-cgi.exe > nul  

exit  


五、在D:\work\soft\php\www下建立 index.php

<?php

2 echo "Hello PHP7!";

3 ?>

六、訪問瀏覽器

http://localhost/index.php

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.