手工安装步骤

本安装指南指导手动在一个 Microsoft Windows 的 web 服务器下安装和配置 PHP。安装前需要从 http://www.php.net/downloads.php 下载 PHP 的 ZIP 二进制发布包。

虽然目前有很多多合一的安装包,而且也发布了一个 Microsoft Windows 的 PHP 安装程序,但是仍然建议用户花些时间自己手动安装 PHP。因为这样才可以更加了解这套系统,并能够在需要的时候更方便的安装 PHP 扩展。

从旧版本的 PHP 升级: 上一版的手册建议将 ini 和多个 DLL 文件移动到系统文件夹(例如 C:\WINDOWS)。这一步骤虽然简化了安装过程,却导致升级上的困难。建议在使用新版本的 PHP 前删除所有这些文件(比如从 Windows 系统文件夹删除 php.ini 和 PHP 相关的 DLL 文件)。务必在删除前备份这些文件,因为这一操作可能破坏整个系统。原有的 php.ini 在安装新版本的 PHP 时也可用来参考。不久用户便会明白,安装 PHP 最好的方式便是将所有 PHP 有关的文件都放入同一目录,并在系统的 PATH 环境变量中设置此目录。

MDAC 需求: 如果使用 Microsoft Windows 98/NT4,需要下载适用于系统最新版本的 Microsoft Data Access Components(MDAC)。MDAC 可在 http://msdn.microsoft.com/data/ 下载。需要 MDAC 的原因是 Windows 二进制包中编译进了 ODBC 支持。

不论何种 web 服务器,都需要先进行以下步骤:

将 PHP 压缩包释放到选择的目录中。若使用 PHP 4,可以解压缩到 C:\,压缩包会被释放到一个类似 php-4.3.7-Win32 的新目录中。若使用 PHP 5,请解压缩到 C:\php,因为其 ZIP 包内没有类似 php-4.3.7-Win32 的目录信息。可以选择其它的路径但最好不要用中间有空格的路径(例如:C:\Program Files\PHP 就不太好),如果这样做有些 web 服务器会崩溃。

解压缩后的目录对应 PHP 4 和 5 是不同的。它们的目录结构分别为:

例子 6-1. PHP 4 目录结构

c:\php
   |
   +--cli
   |  |
   |  |-php.exe           -- CLI 可执行程序 - 仅使用在命令行脚本
   |
   +--dlls                -- 某些扩展需要的 DLL 文件
   |  |
   |  |-expat.dll
   |  |
   |  |-fdftk.dll
   |  |
   |  |-...
   |
   +--extensions          -- PHP 的扩展 DLL 文件
   |  |
   |  |-php_bz2.dll
   |  |
   |  |-php_cpdf.dll
   |  |
   |  |-..
   |
   +--mibs                -- SNMP 支持文件
   |
   +--openssl             -- Openssl 支持文件
   |
   +--pdf-related         -- PDF 支持文件
   |
   +--sapi                -- SAPI(服务器模块支持)DLL 文件
   |  |
   |  |-php4apache.dll
   |  |
   |  |-php4apache2.dll
   |  |
   |  |-..
   |
   +--PEAR                -- PEAR 的初始复本
   |
   |
   |-go-pear.bat          -- PEAR 安装脚本
   |
   |-..
   |
   |-php.exe              -- CGI 可执行文件
   |
   |-..
   |
   |-php.ini-dist         -- 默认的 php.ini 设置
   |
   |-php.ini-recommended  -- 推荐的 php.ini 设置
   |
   |-php4ts.dll           -- 核心 PHP DLL 文件
   |
   |-...

或:

例子 6-2. PHP 5 目录结构

c:\php
   |
   +--dev
   |  |
   |  |-php5ts.lib
   |
   +--ext                 -- PHP 的扩展 DLL 文件
   |  |
   |  |-php_bz2.dll
   |  |
   |  |-php_cpdf.dll
   |  |
   |  |-..
   |
   +--extras
   |  |
   |  +--mibs             -- SNMP 支持文件
   |  |
   |  +--openssl          -- Openssl 支持文件
   |  |
   |  +--pdf-related      -- PDF 支持文件
   |  |
   |  |-mime.magic
   |
   +--pear                -- PEAR 的初始复本
   |
   |
   |-go-pear.bat          -- PEAR 安装脚本
   |
   |-fdftk.dll
   |
   |-..
   |
   |-php-cgi.exe          -- CGI 可执行文件
   |
   |-php-win.exe          -- 执行脚本时不弹出命令提示行窗口
   |
   |-php.exe              -- CLI 可执行程序 - 仅使用在命令行脚本
   |
   |-..
   |
   |-php.ini-dist         -- 默认的 php.ini 设置
   |
   |-php.ini-recommended  -- 推荐 php.ini 设置
   |
   |-php5activescript.dll
   |
   |-php5apache.dll
   |
   |-php5apache2.dll
   |
   |-..
   |
   |-php5ts.dll           -- 核心 PHP DLL 文件
   |
   |-...

请注意它们之间的不同和相似之处。PHP 4 和 PHP 5 都有一个 CGI 可执行文件、一个 CLI 可执行文件和服务器模块,但是它们位于不同的文件夹和/或有着不同的命名。PHP 4 将服务器模块放在 sapi 文件夹,而 PHP 5 并没有此目录,它的服务器模块文件位于 PHP 根文件夹中。PHP 5 的扩展支持 DLL 文件也并没有放在一个单独的目录中。

注: 在 PHP 4 中,需要将位于 dllsapi 文件夹中的文件移动到主文件夹中(例如 C:\php)。

下面是 PHP 4 和 PHP 5 附带的服务器模块列表:

  • sapi/php4activescript.dll (php5activescript.dll) - ActiveScript 引擎,允许将 PHP 嵌入 Windows 应用程序中。

  • sapi/php4apache.dll(php5apache.dll) - Apache 1.3.x 模块。

  • sapi/php4apache2.dll(php5apache2.dll) - Apache 2.0.x 模块。

  • sapi/php4isapi.dll(php5isapi.dll) - ISAPI 模块,支持 ISAPI 兼容的 web 服务器,比如 IIS 4.0/PWS 4.0 或更新版本。

  • sapi/php4nsapi.dll(php5nsapi.dll) - Sun/iPlanet/Netscape 服务器模块。

  • sapi/php4pi3web.dll(PHP 5 无此模块) - Pi3Web 服务器模块。

服务器模块比 CGI 可执行程序提供了更好的性能和更多的功能。CLI 版本是为使用 PHP 命令行脚本而设计的。关于 CLI 的更多信息可以在 PHP 的命令行模式一章中找到。

警告

SAPI 模块在 4.1 中有较多的增强。但是,在老系统中可能会产生服务器错误,或导致服务器的其它模块停止工作,比如 ASP。

CGI 和 CLI 可执行文件以及 web 服务器模块都需要 php4ts.dllphp5ts.dll)。必须确认该文件可以在 PHP 安装路径中找到。对该 DLL 的搜索顺序为:

  • 调用 php.exe 时所在的目录,或者若使用 SAPI 模块时,web 服务器的目录(例如 C:\Program Files\Apache Group\Apache2\bin)。

  • 任何在 Windows 的 PATH 环境变量中指定的目录。

要让 php4ts.dll / php5ts.dll 能正确被搜索到,有下面三个选择:复制该文件到 Windows 系统目录,复制该文件到 web 服务器的目录,或者把 PHP 目录(例如 C:\php)添加到 PATH 环境变量中。为了将来更好的维护,建议使用最后一个选择,将 PHP 目录添加到 PATH 环境变量中,因为这样更便于将来升级 PHP。在相应的常见问题解答项目中可以了解如何将 PHP 目录添加到 PATH 环境变量中。

下一步是为 PHP 设置一个有效的配置文件,php.ini。在 ZIP 包中有两个 ini 文件,php.ini-distphp.ini-recommended。建议使用 php.ini-recommended,因为在该文件中优化了性能和安全。请仔细阅读该文件中的注释,因为它从 php.ini-dist 修改而来,会对设置产生较大的影响。例如将 display_errors 设置为 off,将 magic_quotes_gpc 设置为 off。除了阅读这些部分,还可以学习一下 ini 设置,并手动设置每一个配置项目。如果想要最安全的设置,这是最好的方法,虽然 PHP 在默认配置下也是很安全的。复制所选择的 ini 文件到 PHP 能找到的目录中,并将其重命名为 php.ini。PHP 搜索 php.ini 的路径在配置文件一节已有介绍。

如果使用 Apache 2,更简单的选择是使用 PHPIniDir 指令(请阅读在 Apache 2 下的安装);若不是,最好的选择是设置 PHPRC 环境变量。它在此常见问题解答项目中进行了解释。

注: 如果在 Windows NT、2000、XP 或 2003 中使用 NTFS 分区,请确认运行 web 服务器的用户有权限读取 php.ini(例如将其设置为 Everyone 可读)

下面的步骤是可选的:

  • 编辑新的 php.ini 文件。如果计划使用 OmniHTTPd,不要执行下一步。设置 doc_root 并指向 web 服务器的 document_root。例如:

    doc_root = c:\inetpub\wwwroot // for IIS/PWS
    
    doc_root = c:\apache\htdocs // for Apache

  • 选择 PHP 装载的扩展库。请阅读关于 Windows 扩展一节以了解如何设置扩展库,以及哪些功能已经内置无需扩展库。请注意建议在全新安装时先不要在 php.ini 中加载任何扩展库,首先要保证 PHP 自身能够正常工作。

  • 在 PWS 和 IIS,可以设置 browscap 配置:在 Windows 9x/Me 中指向 c:\windows\system\inetsrv\browscap.ini,在 NT/2000 中指向 c:\winnt\system32\inetsrv\browscap.ini,在 XP 中指向 c:\windows\system32\inetsrv\browscap.ini。要得到最新版本的 browscap.ini,请阅读如下常见问题解答项目

PHP 现在已经安装在系统中了。接下来一步是选择一个 web 服务器,并为之启用 PHP。请在本章目录中选择一个 web 服务器以了解更详细的安装步骤。


add a note add a note User Contributed Notes
Chris
12-Oct-2006 10:58
RE:  phpmanual at pbb dot dds dot nl  @ 07-Oct-2004 11:29

You are correct.  I just had the same issue; I was following the PHP installation instructions and some very helpful WIMP instructions.

I was trying to keep things tidy by putting my PHP directory in C:\Program Files\PHP.  I set the PATH variable, ISAPI filter config and extension in Application Configuration, but was getting the "Specified module could not be found" error.

Changed the PHP directory to C:\PHP and reconfigured everything, did an iisreset, and it started working immediately.

Good catch, and thank you!
mega-squall at caramail dot com
23-Jul-2006 05:19
Remember to enter FULL PATH in the extension_dir parameter in php.ini ! Using only "./ext/" or any relative path will have your PHP failing to load extensions when called by Apache. That's quite tricky 'cause extensions are working when PHP is used through command line ...
Jason Greene
04-May-2006 09:06
If you are running websites within an Application Pool (which is now the default for IIS6 under 2K3) you need to make sure that your PHP directory (e.g. C:\PHP) has read permissions for the user assigned to the Application Pool.

1. In the IIS snap-in, choose Application Pools
2. Right-click on DefaultAppPool (or other, if you have one defined) and choose Properties
3. Click the Identity tab
4. Make a note of the user name set as the security account for this application pool (e.g. "Network Service")
5. Browse to your PHP directory and grant that user read permissions for the entire directory.

In my case, I had to add permissions for the user "NETWORK SERVICE" to get PHP scripts to work. Otherwise I received 401/403 authorization errors when trying to load them in a remote browser.

Note also that first tried adding IUSR permissions to the PHP directory, but that had no effect.
Ben
07-Apr-2006 06:17
In the Note Titled "Windows Server 2003 (x64 bits) + IIS 6.0" in step 1 when adding your new .php extension, it will not work unless after you click on the "Home Directory" you make sure that your "Execute permissions:" are set to "Scripts Only".

By default, on my machine, the permissions were set to "None" not allowing php to run.

Also, for more security it might be wise to Add the new extension just to your default site instead of the whole Web Sites folder in IIS. This would only apply if you were hosting multiple sites and had a site you didn't want scripts to run on.
Tom
14-Feb-2006 01:54
On this page and the FAQ they point out that to reset the Windows PATH variable to include your php dir, you need to completely restart the machine.

If you can't afford to do that (installing on a live server for example), you can use the setx.exe tool from the Windows Resource Kit (google it). Like so:

c:\pathtoresourcekit> setx.exe PATH "%PATH%;c:\php" \m
Windows Server 2003 (x64 bits) + IIS 6.0
01-Feb-2006 07:16
1. Add new extension (.php)

   * Expand the local computer in the left pane
   * Right-click on "Web Sites" in the left pane, then click "Properties" in the menu that pops up
   * Flip top the "Home Directory" tab
   * Click "Configuration"
   * Flip to the "Mappings" tab
   * Click "Add..."
   * Enter the full path to php5isapi.dll in the "Executable" textbox (Browse... to find it more easily if you need to)
   * Enter ".php" in the "Extension" textbox
   * Select radial button "Limit to", enter "GET,POST,HEAD"
   * Click "OK" all the way out

2. Verify php5isapi.dll is allowed

You must verify that the versions of php5isapi.dll that you want to use are allowed.

   2.1. In Internet Information Services (IIS) Manager, in the left-hand column, click the Web Services Extensions node and verify php5isapi.dll is allowed and all other Web Service Extensions are prohibited.
   2.2. If the version of php5isapi.dll that you want to use does not appear in the list, follow the instructions to enable it and then repeat this procedure:

Go into IIS
Below all of the websites is a folder: Web Service Extensions
In blue, to the lower left, is a choice: Add A New Web Service Extension
Add PHP/PHP5ISAPI.dll
Choose To ALLOW it.

   2.3 If the version of php5isapi.dll you want to use appears on the list but is not allowed, right click the version of php5isapi.dll you want to allow and click Allow.

3. Configuring IIS for 32-Bit Emulation Mode (THIS IS MOST IMPORTANT!!!!)

3.1. If you are installing IIS on x64-based editions of Windows Server 2003 or Windows Server 2003 R2, IIS must be configured to run in 32 bit emulation mode. Perform the following procedure on each front-end Web server running an x64-based edition of Windows Server 2003.
Configure Internet Information Services (IIS) for 32-bit mode

   1. Click Start, and then click Run.
   2. In the Open box, type cmd, and then click OK.
   3. In the command prompt window, navigate to the %drive%:\Inetpub\Adminscripts folder, where %drive% is the drive in which Windows Server 2003 is installed.
   4. In the Adminscripts folder, type the following command:

     cscript adsutil.vbs set w3svc/AppPools/Enable32bitAppOnWin64 1

     Note  The value "1" for Enable32bitAppOnWin64 specifies 32-bit mode, whereas the value "0" specifies 64-bit mode.
   5. Press ENTER.
   6. Type iisreset and then press ENTER.
   7. Close the command prompt window.
   8. Re-star System.

Note  The Run WWW service in IIS 5.0 isolation mode check box is only selected if you have upgraded to IIS 6.0 on Windows Server 2003 from IIS 5.0 on Windows 2000. New installations of IIS 6.0 use IIS 6.0 worker process isolation mode by default.
patatraboum at nospam dot com
27-Dec-2005 10:09
IIS + PHP

- The browser can't find your php code like localhost/dir/dir_code.php from any virtual directory (404 error)
- You are sure the code exists
You may rename it with a .html extension and check if it displays
- Process of your php code like localhost/root_code.php is ok from the root directory

It may come from the doc_root directive in php.ini whitch should be set to blank :

doc_root =

Then restart IIS to reload php.ini
some dude @ some place
05-Nov-2005 12:57
on two recent installation attempts on iis6 on win2k3 i followed the php manual and windows configuration steps exactly and php would still not run.

on the first install i had to give the USER account (not IUSR) read execute permissions to this file, c:\php\sapi\php4isapi.dll. using filemon i saw that it was being accessed and access was denied.

steps:
- right click on this file > properties > security > add > location (select the server -not domain if listed) > advanced > find now > Users (usually the last item) > click OK
- select Read & Execute > apply

also a complete computer restart was required in each install
Bill dot Rook at Gmail dot com
19-Sep-2005 01:09
doc_root = ".;c:\inetpub\wwwroot" does seem to work with virtual websites. This might be a better option then commenting out the line.
Jason
10-Sep-2005 07:54
For me atleast, the steps for installing php 5 on IIS 6 on windows 2003 seemed to get buried with the other setups. I found it difficult to quickly look through and make sure I covered every step. So I created a clean step by step tutorial with screenshots:
http://psdforums.com/article.php?a=9
atomictaco at atomic-taco dot com
11-Jul-2005 12:17
In response to phpmanual at pbb dot dds dot nl:

You are absolutly correct.  I found this out while trying to install PHP4 with Apache2 on XPPro.  Here are 3 general guidelines that I have found to be correct:

- Path may not have spaces.  Change C:\Program Files to C:\Progra~1  If you don't understand this, go to start-->run-->command (not cmd).  Type cd\ and hit enter.  Then type dir.  You should see all your directory names there.

- Paths should not be enclosed by quotes.

- Use forward slashes (/) and not backslashes (\)
thierry dot bo at nxextxcxoxuxrxrxixexr dot com
20-Dec-2004 08:50
With PHP 4.3.x and apache 1.3.x on windows, PHPRC is used only if php is installed as cgi. With module, no matter using setenv in httpd.conf or PHPRC as windows environment variable, it is not used.
cpz at akik-ffm dot de
20-Dec-2004 02:24
In the above, "the web server's directory" means the directory where the server executable lives, for example for the Apache installation on my XP box this is "\program files\apache group\apache2\bin" and NOT just "\program files\apache group\apache2".

But it's probably best to tell your web server where PHP's ini file is stored, for example via PHPIniDir for Apache's http.conf.
mic42 at users dot sourceforge dot net
01-Dec-2004 12:09
To install PHP as CGI under the Tcl Webserver Tclhttpd follow the instructions at:
http://wiki.tcl.tk/12130
chuacheehow at gmail dot com
08-Oct-2004 08:55
My experience with IIS 5.1 is that the doc_root directive be commented in order for virtual directories to recognise PHP files (with PHP installed as CGI).
phpmanual at pbb dot dds dot nl
07-Oct-2004 09:29
Okay, I'm a total newbie to this, so my findings may be wrong, but this is what I found out.

The manual says "do not have spaces in the path (like C:\Program Files\PHP) as some web servers will crash if you do". Indeed, when using this with PHP5 on WinXP, I got the error message "The specified module could not be found."
However, the problem seems not to lie in the SPACE in the pathname, but in the QUOTES that Windows adds when a space is in the pathname! This is what I found:

"C:\Program Files\php5\php5isapi.dll" -- doesn't work
C:\php5\php5isapi.dll -- works
"C:\php5\php5isapi.dll" -- doesn't work
C:\Progra~1\php5\php5isapi.dll -- works
"C:\Progra~1\php5\php5isapi.dll" -- doesn't work
C:\Program Files\php5\php5isapi.dll -- doesn't work, because it's not accepted by Internet Information Services

I don't know if this all is a problem with Internet Information Services or with PHP, but it would be nice if it was more documented in the PHP manual.
php dot user dot com
29-Aug-2004 04:43
After having the same problem as specifed below with "No input file specified". I changed the doc_root as mentioned.

This is fine if all php scripts are going to be run from the c:\inetpub\wwwroot directory. To enable it for multiple websites where the root directories are all different simply leave the doc_root attribute in the php.ini file blank.

This is for the isapi version not cgi implementation. It also means you don't have to set IUSR or IWAM access to the PHP root directory.