使用 Visual Studio(无 WebMatrix)在 IIS Express 上启用 PHP
我正在开发这个 Web 应用程序,它主要是 .NET,但一部分是用 PHP 编写的。在我的开发环境中,IIS Express 是我选择的 Web 服务器,因此我更愿意让 PHP 和 .NET 在此环境中协同工作。
第一次天真的尝试:只需将 PHP 脚本放入网站,然后将它们加载到浏览器中。结果是 HTTP 错误 404.21 - Not Found
,并提供以下建议:
- 安装 PHP 并正确配置处理程序。
- 为此网站安装并启用 PHP。
- 如果您使用的是 WebMatrix,请按照以下步骤启用 PHP:
- 在 WebMatrix 中打开网站。
- 选择“站点”工作区并点击“设置”。
- 选中“启用 PHP”复选框以安装并启用 PHP。
不使用 WebMatrix,这对我没有任何帮助。然后,我继续在 Google 上深入搜索与 IIS Express 和 PHP 相关的所有内容。从我读到的内容来看,这应该是可行的,但我发现的有关该主题的所有内容似乎都假设我的 IDE 是 WebMatrix。事实并非如此。
有谁知道是否可以在 IIS Express 上安装并将其配置为与基于 Visual Studio 的网站一起使用,而无需安装 WebMatrix?如果是,怎么办?
I am working on this web application which is mostly .NET, but a part is written in PHP. In my development environment, IIS Express is my web server of choice, so I would prefer to get PHP and .NET work together in this environment.
First naive attempt: Just throw the PHP scripts into the web site, and load them in a browser. The result is an HTTP Error 404.21 - Not Found
with the following suggestions:
- Install PHP and configure handlers correctly.
- Install and enable PHP for this web site.
- If you are using WebMatrix, follow these steps to enable PHP:
- Open the web site in WebMatrix.
- Select the Site workspace and click on Settings.
- Check the "Enable PHP" checkbox to install and enable PHP.
Not using WebMatrix, this does nothing to help me. I then proceed to do a deep trawl of anything related to IIS Express and PHP on Google. From what I read, it should be doable, but everything I find about the subject seems to assume that my IDE is WebMatrix. It isn't.
Does anyone know if it is possible to install on IIS Express and configure it to work with a Visual Studio based web site, without having to install WebMatrix? If yes, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
IIS Express 支持没有 Web 矩阵的 PHP。您可以仅安装 IIS Express 并使其与 Visual Studio 一起使用。为此,您需要 Visual Studio 2010 SP1。
从此链接下载 IIS Express:Internet 信息服务 (IIS) 7.5 Express
在 Visual Studio 中将网站/Web应用程序项目配置为使用 IIS Express。看看这个线程 如何配置网站项目以使用 IIS Express?
要在 IIS Express 上启用 PHP,请安装 PHP 并更新 applicationhost.config (%userprofile%\documents\iisexpress\config\applicationhost.config)。您可以使用位于 IIS Express 安装文件夹中的 appcmd.exe 版本来执行此操作。请参阅此链接 了解详细信息。
如果所有内容都安装在美国英语版本 Windows 的默认位置,则命令将为:
请注意,如果 php-cgi.exe 的完整路径中有空格,则必须将路径用单引号和双引号引起来,如示例中所示多于。
最后,如果您没有 VS 2010 SP1,也许您应该看看这篇文章: 使用 IIS Express 调试您的 .NET Web 项目
IIS Express supports PHP without Web matrix. You can install just IIS Express alone and make it work with Visual Studio. For this you need Visual Studio 2010 SP1.
Download IIS Express from this link: Internet Information Services (IIS) 7.5 Express
In Visual Studio configure your WebSite/WebApplication project to use IIS Express. Take a look at this thread How do I configure a website project to use IIS Express?
To enable PHP on IIS Express, install PHP and update applicationhost.config (%userprofile%\documents\iisexpress\config\applicationhost.config). You can use the version of appcmd.exe located in IIS Express installation folder for doing this. See this link for details.
If everything is installed in the default places for US English versions of Windows the commands will be:
Note that if there are spaces in the full path of php-cgi.exe, you MUST enclose the path in single and double quotes as in the example above.
Finally, if you don't have VS 2010 SP1, probably you should take a look at this post: Debug Your .NET Web Project With IIS Express
另一种选择是使用 Web 平台安装程序。
开放式 Web 平台安装程序(可以从 http://go.microsoft.com/fwlink/?LinkId= 下载255386)
搜索 PHP for IIS Express
单击安装
Web 平台安装程序将为您安装 PHP 并配置 IIS Express。
Another option is to use Web Platform Installer.
open Web Platform installer (can be downloaded from http://go.microsoft.com/fwlink/?LinkId=255386)
search for PHP for IIS Express
click Install
Web Platform Installer will install PHP and configure IIS Express for you.
较新版本的 Visual Studio 维护 IIS Express 配置文件“applicationhost.config”的单独副本。大多数在线说明都会向您展示如何定位主 applicationhost.config 文件,该文件没有任何效果,因为 VS2017 维护一个单独的副本并在启动 IIS Express 时使用此副本。为了在这种情况下启用 PHP,我必须编辑 VS2017 的私有副本。
先决条件 - 使用 Web 平台安装程序安装 PHP。 (您不需要 IIS Express,只需下载常规 PHP。)您可以使用 x86 或 x64。这会将 PHP 安装到 C:\Program Files\ 或 C:\Program Files (x86)\ 中,具体取决于您选择的位置。您也可以简单地从他们的网站获取 PHP。
找到项目的 applicationhost.config。它位于隐藏的 .vs 子文件夹中。例如 C:\MyProject\.vs\applicationhost.config
从命令窗口运行以下命令,将您的路径替换为项目文件夹和安装的 PHP 二进制文件。
或者,您可以简单地在文本编辑器中编辑项目的 applicationhost.config 并添加以下部分。
system.webServer/fastCGI
system.webServer/handlers
需要明确的是,编辑 IIS Express\AppServer\applicationhost.config 或 %appdata% 文件夹中的配置不会有帮助除非您正在执行一些高级操作,例如在 Visual Studio 之外启动 IIS Express。
Newer versions of Visual Studio maintain a separate copy of IIS Express's configuration file "applicationhost.config". Most of the instructions online show you how to target the master applicationhost.config file which has no effect because VS2017 maintains a separate copy and uses this copy when starting IIS express. To enable PHP in this scenario, I had to edit VS2017's private copy.
Prerequisite - Use the web platform installer to install PHP. (You don't need the one for IIS Express, just the regular PHP download.) You can use x86 or x64. This will install PHP into either C:\Program Files\ or C:\Program Files (x86)\ depending on which one you choose. You could also simply grab PHP from their website.
Locate your project's applicationhost.config. It is located in a hidden .vs subfolder. For example C:\MyProject\.vs\applicationhost.config
Run the following commands from a command window, substituting your paths for the project folder and the PHP binaries you installed.
Alternatively, you can simply edit the project's applicationhost.config in a text editor and add the following sections.
system.webServer/fastCGI
system.webServer/handlers
To be clear, editing the IIS Express\AppServer\applicationhost.config or the one in your %appdata% folder will not help unless you're doing something advanced like starting IIS Express outside Visual Studio.
如果您通过 Visual Studio 运行 IIS,则需要使用 php 处理程序更新解决方案目录中的 .vs\config\applicationhost.config
If you are running IIS through Visual Studio, you need to update the .vs\config\applicationhost.config in your solution directory with the php handler