windows下nginx + php配置

來源:互聯網
上載者:User
windows上nginx + php配置

apache下載失敗,正好對apache那種把php解譯器做成module當動態庫載入到自身進程的預設做法不太滿意,網上大家又都說nginx好,就使用nginx+php+mysql配置一下。

?

環境:Windows 7 32bit

版本:nginx 1.2.3,php-5.4.7-Win32-VC9-x86,mysql 5.5.27

?

nginx和php都是下載後解壓縮就可以用,mysql需要安裝。

?

在php解壓目錄下,將php.ini-development拷貝到php.ini檔案,同時啟用其中的mysql模組:

?

;extension=php_exif.dll      ; Must be after mbstring as it depends on itextension=php_mysql.dll;extension=php_mysqli.dll;extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client;extension=php_oci8_11g.dll  ; Use with Oracle 11gR2 Instant Client;extension=php_openssl.dll;extension=php_pdo_firebird.dllextension=php_pdo_mysql.dll;extension=php_pdo_oci.dll

?

注意,必須將指定extension目錄那一行的注釋去掉,否則php不會自動使用ext作為預設值來載入這些擴充:

?

; Directory in which the loadable extensions (modules) reside.; http://php.net/extension-dir; extension_dir = "./"; On windows:extension_dir = "ext"
?

?

然後啟動php內建的cgi程式,在9000連接埠監聽nginx發過來的請求:

?

php-5.4.7-Win32-VC9-x86> php-cgi.exe -b 127.0.0.1:9000
?

在nginx目錄下,修改conf/nginx.conf,啟用fastcgi:

?

        # 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;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            #fastcgi_param  SCRIPT_FILENAME  D:/software/nginx-1.2.3/html$fastcgi_script_name;            include        fastcgi_params;        }

?

注意,預設設定檔中,fastcgi_param SCRIPT_FILENAME配置的是/scripts$fastcgi_script_name;,表示從這裡找.php檔案。這個預設配置是錯的,使用這個配置時,訪問php頁面會返回“No input file specified”錯誤。需要改成下面這兩種:或者用$document_root,表示當前根web路徑,或者直接用根web路徑的絕對路徑。

?

一般還要將index.php放到根路徑的index中:

        location / {            root   html;            index  index.html index.htm index.php;        }
?

?

配置完成後,啟動nginx:

?

D:\software\nginx-1.2.3> start nginx 
?

在document_root建立一個簡單的php檔案,測試一下:

?


?

在本地驗證一下:http://localhost:8080/index.php,一般都可以開啟訪問,並可以查看其中的myspartan1

  • 瀏覽: 15986 次
  • 性別:
  • 來自: 深圳

最近訪客 更多訪客>>

dylinshi126

wangshuqin0716

風沙星辰

hbezwwl
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.