如何在Windows Server 2008的IIS 7上安装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 7 on your Windows Server 2008 system.

PHP是Web上最流行的开发平台之一,它为许多流行的应用程序和网站(如Facebook,WordPress和Joomla)提供支持。 尽管大多数系统都是“设计”为在运行Apache Web ServerLinux系统上使用的,但是您可以在Windows Server 2008系统上通过IIS 7部署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 7, the non thread safe binaries should be used.

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

image

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”。

image

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 7 system:

在记事本中打开“ php.ini”文件并根据需要进行配置。 开箱即用,我们复制的生产配置已预先配置,以使PHP Team觉得对生产服务器有利。 您需要进行一些更改才能为IIS 7系统配置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 7以运行FastCGI (Configuring IIS 7 to Run FastCGI)

Internet Information Services (IIS) 7 includes the FastCGI framework as part of the installation package. To make sure it is enabled in your IIS 7 installation, check the Role Services under Server Manager > Roles > Web Server.

Internet信息服务(IIS)7包含FastCGI框架作为安装包的一部分。 要确保在IIS 7安装中启用了该功能,请在“服务器管理器”>“角色”>“ Web服务器”下检查“角色服务”。

image

Make sure the “CGI” option is installed under the “Application Development” section. If it is not, enable this feature and update your IIS 7 installation.

确保在“应用程序开发”部分下安装了“ CGI”选项。 如果不是,请启用此功能并更新IIS 7安装。

image

Once IIS is set, install the IIS 7 Administration Pack. If you do not use the “Typical” setup then make sure you have the “FastCGI” option set to install. This package installs the FastCGI configuration interface inside the IIS Manager.

设置完IIS后,安装IIS 7管理包。 如果您不使用“典型”设置,请确保已设置“ FastCGI”选项来安装。 该程序包在IIS管理器中安装FastCGI配置界面。

image

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

Once IIS 7 is setup with all the required features, we just need to configure it to run PHP. First, we configure FastCGI to work with PHP under the “FastCGI Settings” option (this feature is installed as part of the IIS 7 Administration Pack).

使用所有必需的功能设置完IIS 7后,我们只需对其进行配置即可运行PHP。 首先,我们在“ FastCGI设置”选项下将FastCGI配置为与PHP一起使用(此功能作为IIS 7管理包的一部分安装)。

image

In the FastCGI Settings screen, add an application.

在“ FastCGI设置”屏幕中,添加一个应用程序。

image

Set the path to the ‘php-cgi.exe’ executable located in the folder where you extracted the PHP Windows binaries. Additionally, change the “InstanceMaxRequests” to a value higher than the default (i.e. 5000). Under the “EnvironmentVariables” setting, click the ellipses button to configure additional options.

将路径设置为“ php-cgi.exe”可执行文件,该文件位于您提取PHP Windows二进制文件的文件夹中。 另外,将“ InstanceMaxRequests”更改为高于默认值(即5000)的值。 在“ EnvironmentVariables”设置下,单击省略号按钮以配置其他选项。

image

Add a new variable named “PHP_MAX_REQUESTS” and set the value to the same amount as the “InstanceMaxRequests” setting above.

添加一个名为“ PHP_MAX_REQUESTS”的新变量,并将其值设置为与上面的“ InstanceMaxRequests”设置相同的值。

image

Apply all settings until you get back to the primary IIS Manager screen.

应用所有设置,直到返回到“ IIS管理器”主屏幕。

Next, we have to map how PHP scripts are executed by IIS which is configured in “Handler Mappings”.

接下来,我们必须映射在“处理程序映射”中配置的IIS如何执行PHP脚本。

image

In the Handler Mappings, add a new module mapping.

在处理程序映射中,添加一个新的模块映射。

image

Set the module’s request path to PHP files (*.php) with the module interface “FastCgiModule”. Set the executable to the same file as what was configured in the FastCGI settings above. Assign a friendly name to this mapping, such as PHP, and click Ok.

使用模块接口“ FastCgiModule”将模块的请求路径设置为PHP文件(* .php)。 将可执行文件设置为与上述FastCGI设置中配置的文件相同的文件。 为该映射分配一个友好的名称,例如PHP,然后单击“确定”。

image

When you get the confirmation prompt, answer “Yes” to confirm you want PHP to run as a FastCGI application.

当您收到确认提示时,请回答“是”以确认您希望PHP作为FastCGI应用程序运行。

image

Apply all your changes, close and restart IIS to make sure the new settings take effect.

应用所有更改,关闭并重新启动IIS,以确保新设置生效。

image

Once this is done, there is a Microsoft hotfix available (a link is available in the links section) which addresses some issues with PHP when running under IIS 7. These should be installed on your web server to ensure PHP functions properly through FastCGI.

完成此操作后,将提供一个Microsoft修补程序(链接部分中的链接),该修补程序解决了在IIS 7下运行时PHP的一些问题。这些应安装在Web服务器上,以确保PHP通过FastCGI正常运行。

测试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(); ?>

image

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现在已启动并在您的计算机上运行。

image

结论 (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 7 Administration Pack

下载IIS 7管理包

Download PHP Hotfix for IIS 7 FastCGI (x86 / x64)

下载IIS 7 FastCGI( x86 / x64 )PHP修补程序

翻译自: https://www.howtogeek.com/50432/how-to-install-php-on-iis-7-for-windows-server-2008/

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值