如何在Windows Server 2003的IIS 6上安装PHP

One of most popular development platforms on the web is PHP which powers many popular applications and sites such as Facebook, WordPress and Joomla. While most of these systems are ‘designed’ to be used on a Linux system running the Apache Web Server, you can deploy PHP applications via IIS 6 on your Windows Server 2003 system.

PHP是Web上最流行的开发平台之一,它为许多流行的应用程序和网站(如Facebook,WordPress和Joomla)提供支持。 尽管大多数系统都是“设计”为在运行Apache Web Server的Linux系统上使用的,但是您可以通过IIS 6在Windows Server 2003系统上部署PHP应用程序。

配置PHP (Configuring PHP)

In order for Windows to run PHP code, the PHP binary files need to be copied to your system. No installation is required, however some configuration must be done in order for it to properly run. The first step is to download the PHP Windows Binaries and extract them (i.e. ‘C:PHP’). For IIS 6, the non thread safe binaries should be used.

为了使Windows运行PHP代码,需要将PHP二进制文件复制到您的系统中。 不需要安装,但是必须进行一些配置才能使其正常运行。 第一步是下载PHP Windows Binaries并将其解压缩(即“ C:PHP”)。 对于IIS 6,应使用非线程安全的二进制文件。

如何在Windows Server 2003的IIS 6上安装PHP

Copy the ‘php.ini-production’ file from the extracted files paste it into the Windows directory. In the Windows directory, rename this file to ‘php.ini’.

从解压缩的文件中复制“ php.ini-production”文件,然后将其粘贴到Windows目录中。 在Windows目录中,将此文件重命名为“ php.ini”。

如何在Windows Server 2003的IIS 6上安装PHP

Open the ‘php.ini’ file in Notepad and configure it as needed. Out of the box, the production configuration we copied is preconfigured for what the PHP Team feels is good for a production server. There are a few changes you will need to make to configure PHP for your IIS 6 system:

在记事本中打开“ php.ini”文件并根据需要进行配置。 开箱即用,我们复制的生产配置已预先配置,以使PHP Team觉得对生产服务器有利。 您需要进行一些更改才能为IIS 6系统配置PHP:

  • Uncomment and set the key, cgi.force_redirect = 0

    取消注释并设置**cgi.force_redirect = 0

  • Uncomment the key, fastcgi.impersonate = 1

    取消注释**, fastcgi.impersonate = 1

  • Uncomment and set the key, extension_dir to the ‘ext’ folder in the path PHP was extracted to (i.e. ‘C:PHPext’).

    取消注释,并将**extension_dir设置为PHP提取到的路径中的“ ext”文件夹(即“ C:PHPext”)。
  • Set the key, date.timezone to the time zone of your server (the URL on the line above this key lists the accepted values).

    将**date.timezone设置为服务器的时区(此**上方行上的URL列出了可接受的值)。

At this point, your Windows system can run PHP scripts from the command line using the ‘php.exe’ tool.

此时,您的Windows系统可以使用“ php.exe”工具从命令行运行PHP脚本。

安装IIS 6 FastCGI扩展 (Installing the IIS 6 FastCGI Extension)

In order for Internet Information Services (IIS) 6 to execute and serve PHP scripts, some additional configuration is required. In this guide, we will install PHP on IIS using the FastCGI interface which provides a good balance of stability and performance. Since FastCGI is not included with IIS 6 be default, we need to download and install it.

为了使Internet Information Services(IIS)6执行并提供PHP脚本,需要一些其他配置。 在本指南中,我们将使用FastCGI接口在IIS上安装PHP,以实现稳定性和性能之间的良好平衡。 由于默认情况下IIS 6不包含FastCGI,因此我们需要下载并安装它。

如何在Windows Server 2003的IIS 6上安装PHP

The FastCGI installer does not require any configuration, however once the FastCGI extension is installed we need to configure it to run PHP.

FastCGI安装程序不需要任何配置,但是,一旦安装了FastCGI扩展,我们需要对其进行配置以运行PHP。

Open the file ‘C:WINDOWSsystem32inetsrvfcgiext.ini’ in Notepad and find the ‘Types’ section and enter the configuration information:

在记事本中打开文件“ C:WINDOWSsystem32inetsrvfcgiext.ini”,找到“类型”部分,然后输入配置信息:

[Types] php=PHP

[类型] php = PHP

[PHP] ExePath=C:PHPphp-cgi.exe InstanceMaxRequests=5000 EnvironmentVars=PHP_MAX_REQUESTS:5000

[PHP] ExePath = C:PHPphp-cgi.exe InstanceMaxRequests = 5000 EnvironmentVars = PHP_MAX_REQUESTS:5000

Revise these values as needed according to your environment, but it is important that all of settings have the correct values. Once you are finished, save this file.

根据您的环境,根据需要修改这些值,但是所有设置都必须具有正确的值,这一点很重要。 完成后,保存此文件。

如何在Windows Server 2003的IIS 6上安装PHP

配置IIS以通过FastCGI运行PHP (Configuring IIS to Run PHP via FastCGI)

With both PHP and FastCGI installed and configured, all that is left is to set up IIS 6. When you open the IIS Management Console, under the Web Service Extensions make sure the “FastCGI Handler” is set to allowed.

安装并配置了PHP和FastCGI之后,剩下的就是设置IIS6。当您打开IIS管理控制台时,在Web Service Extensions下,确保将“ FastCGI Handler”设置为允许。

如何在Windows Server 2003的IIS 6上安装PHP

Next, go to the Properties settings for the Web Sites group.

接下来,转到“网站”组的“属性”设置。

如何在Windows Server 2003的IIS 6上安装PHP

On the “Home Directory” tab, click the “Configuration” button.

在“主目录”选项卡上,单击“配置”按钮。

如何在Windows Server 2003的IIS 6上安装PHP

Add a mapping for files with the .php file extension with the executable set to the FastCGI extension DLL.

添加具有.php文件扩展名且可执行文件设置为FastCGI扩展名DLL的​​文件的映射。

如何在Windows Server 2003的IIS 6上安装PHP

Once you have applied all the changes, restart IIS.

应用所有更改后,请重新启动IIS。

如何在Windows Server 2003的IIS 6上安装PHP

测试PHP (Testing PHP)

At this point, your server is ready to go, but just to be sure we can confirm your PHP setup through IIS pretty easily. Create a text file in the directory ‘C:Inetpubwwwroot’ named ‘phpinfo.php’ which simply contains the line:

此时,您的服务器已准备就绪,但是请确保我们可以通过IIS轻松确认您PHP设置。 在目录“ C:Inetpubwwwroot”中创建一个名为“ phpinfo.php”的文本文件,该文件仅包含以下行:

<?php phpinfo(); ?>

<?php phpinfo(); ?>

如何在Windows Server 2003的IIS 6上安装PHP

Finally, browse to the address: ‘http://localhost/phpinfo.php’ on your server and you should see the PHP information page. If the page loads successfully, PHP is now up and running on your machine.

最后,浏览到服务器上的地址:“ http://localhost/phpinfo.php”,您应该看到PHP信息页面。 如果页面成功加载,则PHP现在已启动并在您的计算机上运行。

如何在Windows Server 2003的IIS 6上安装PHP

结论 (Conclusion)

Once you have PHP up and running on your Windows system, you can take advantage of the multitude of PHP based applications available as well as develop and deploy your own.

在Windows系统上启动并运行PHP之后,您就可以利用大量可用的基于PHP的应用程序以及开发和部署自己PHP。

链接 (Links)

Download PHP Windows Binaries (non thread safe)

下载PHP Windows Binaries (非线程安全)

Download IIS 6 FastCGI Extension

下载IIS 6 FastCGI扩展

翻译自: https://www.howtogeek.com/50455/how-to-install-php-on-iis-6-for-windows-server-2003/