在 Windows 上手動(dòng)安裝 PHP

選擇 Web 服務(wù)器

IIS

IIS 是 Windows 內(nèi)置的服務(wù)。在 Windows 服務(wù)器版本上,請(qǐng)使用服務(wù)器管理(Server Manager)來(lái)添加 IIS 規(guī)則。同時(shí)需要設(shè)置 CGI 角色規(guī)則。在 Windows 桌面版本上,需要使用控制面板中的 "添加/刪除程序" 功能來(lái)添加 IIS。請(qǐng)參閱微軟的官方文檔的 ? 詳細(xì)說(shuō)明。 對(duì)于桌面 web app 開(kāi)發(fā)者,你也可以選擇 IIS/Express 或 PHP Desktop。

示例 #1 命令行下配置 IIS 和 PHP

@echo off

REM download .ZIP file of PHP build from http://windows.php.net/downloads/

REM path to directory you decompressed PHP .ZIP file into (no trailing \)
set phppath=c:\php


REM Clear current PHP handlers
%windir%\system32\inetsrv\appcmd clear config /section:system.webServer/fastCGI
REM The following command will generate an error message if PHP is not installed. This can be ignored.
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /-[name='PHP_via_FastCGI']

REM Set up the PHP handler
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI /+[fullPath='%phppath%\php-cgi.exe']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='%phppath%\php-cgi.exe',resourceType='Unspecified']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /accessPolicy:Read,Script

REM Configure FastCGI Variables
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi /[fullPath='%phppath%\php-cgi.exe'].instanceMaxRequests:10000
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phppath%\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']"
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phppath%\php-cgi.exe'].environmentVariables.[name='PHPRC',value='%phppath%\php.ini']"

Apache

有幾個(gè)用于 Windows 的 Apache 版本。 推薦 ApacheLounge 編譯的 Apache,但是其他選項(xiàng)(比如 XAMPP、 WampServer、 BitNami)提供了自動(dòng)安裝工具。 PHP 可以在帶有 mod_php 或者 mod_fastcgi 的 Apache 上使用。 mod_php 需要使用相同版本的 Visual C 和 相同的 CPU (x86 或 x64) 編譯的 Apache TS 版本。

選擇編譯版本

從 Windows 專用站點(diǎn)下載適合產(chǎn)品環(huán)境使用的 PHP 預(yù)編譯版本: ? http://windows.php.net/download/。 所有的編譯都經(jīng)過(guò)優(yōu)化(PGO),并且 QA 和 GA版本都經(jīng)過(guò)徹底測(cè)試。

PHP 編譯版本有四種類型:

  • Thread-Safe(TS) - 線程安全,用于單進(jìn)程 web 服務(wù)器,例如帶有 mod_php 的 Apache

  • Non-Thread-Safe(NTS) - 非線程安全,用于 IIS 和其他 FastCGI web 服務(wù)器(使用帶有 mod_fastcgi 的 Apache),并且推薦命令行腳本也用此版本

  • x86 - 用于 32 位系統(tǒng)。

  • x64 - 用于 64 位系統(tǒng)。