---
title: "Creating PHP Websites with WebMatrix"
author: "netatomy"
date: "2012-08-13T13:59:00Z"
tags: []
slug: "creating-php-websites-with-webmatrix"
draft: false
lastmod: "2012-10-05T11:58:52Z"
id: 1691591
url: "https://zqc.iteye.com/blog/1691591"
---

**Note: WebMatrix now supports PHP "out of the box". You no loger need to do any manual configuration (as detailed in this post) to get PHP support in WebMatrix. For more information, see**[**http://www.microsoft.com/web/webmatrix/features.aspx**](http://www.microsoft.com/web/webmatrix/features.aspx)**.**

Last week, Scott Guthrie (Corporate VP in Microsoft's Developer Division)[announced on his blog the beta release of WebMatrix](http://weblogs.asp.net/scottgu/archive/2010/07/06/introducing-webmatrix.aspx). His postdescribes what[WebMatrix](http://www.microsoft.com/web/webmatrix/)is and how to get started with it, but he focuses mainly on .NET developers. However,hedoes hint at PHP support, particularly support for PHP applications that are available in the[Web Application Gallery](http://www.microsoft.com/web/appgallery/). Ruslan Yakushev followed up with a blog post that delved a bit deeper into PHP support in WebMatrix:[Install PHP Applications with WebMatrix](http://ruslany.net/2010/07/install-php-applications-with-webmatrix/). As I read those posts (and[others](http://blogs.msdn.com/b/webplatform/archive/2010/07/06/hello-webmatrix.aspx)), I was left wondering about the extent of PHP support in WebMatrix (which is what I'll look at in this post). As it turns out, PHP is fully supported, but it requires a little bit of work up front in this beta release of WebMatrix (a smoother experience for PHP developers is planned for the final release). If you want to work on any of the PHP applications that are available in the[Web Application Gallery](http://www.microsoft.com/web/appgallery/), the experience is very smooth – just follow Ruslan's blog post. However, if you just want to see how WebMatrix works as a PHP IDE for building your own sites (and you don’t want to install one of the PHP apps in the app gallery), then here’s what to do:

**1.**Download the Web Platform Installer 3 beta here:[http://www.microsoft.com/web/webmatrix/](http://www.microsoft.com/web/webmatrix/ "http://www.microsoft.com/web/webmatrix/")

**2.**Run the Web PI and click**Install Microsoft WebMatrix**on the**Getting Started**tab. Or, if you want to also install other programs, select**Microsoft WebMatrix Beta**on the**What’s New**tab, then select other programs before proceeding.

> [![image](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/4572.image_5F00_thumb_5F00_2257298C.png "image")](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/3681.image_5F00_77EAF86E.png)

**3.**Launch WebMatrix and click on**Site From Template**:

> [![image](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/3583.image_5F00_thumb_5F00_568B52D2.png "image")](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/3000.image_5F00_68D41994.png)

**4.**Select an**Empty Site**and provide a name for the site (I’m calling my “PHPSite”).

> [![image](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/3515.image_5F00_thumb_5F00_0EC9C9EB.png "image")](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/8080.image_5F00_2F51099D.png)

**5.**In a text editor, open theapplicationhost.configfile located in yourDocuments\\IISExpress8\\configdirectory. Replace the&lt;fastcgi /&gt;element with the following element:

> &lt;fastCgi&gt;  
> &lt;application fullPath="C:\\PHP\\php-cgi.exe"  
> activityTimeout="600"  
> requestTimeout="600"  
> instanceMaxRequests="10000"&gt;  
> &lt;environmentVariables&gt;  
> &lt;environmentVariable name="PHP\_FCGI\_MAX\_REQUESTS"  
> value="10000" /&gt;  
> &lt;environmentVariable name="PHPRC"  
> value="C:\\PHP" /&gt;  
> &lt;/environmentVariables&gt;  
> &lt;/application&gt;  
> &lt;/fastCgi&gt;

> **Note**: thefullpathattribute of theapplicationelement should point to the cgi executable of your PHP installation. The value attribute for the PHPRC environment variable should point to the location of your PHP installation.

**6.**Add the following location element as the last child of theconfigurationelement:

> &lt;location path="PHPSite"&gt;  
> &lt;system.webServer&gt;  
> &lt;handlers&gt;  
> &lt;add name="PHP via FastCGI"  
> path="\*.php" verb="\*"  
> modules="FastCgiModule"  
> scriptProcessor="C:\\PHP\\php-cgi.exe"  
> resourceType="Either" /&gt;  
> &lt;/handlers&gt;  
> &lt;/system.webServer&gt;  
> &lt;/location&gt;

> **Note:**Thepathattribute of thelocationelement should be the name of your site and the value of thescriptProcessorattribute should point to the cgi executable of your PHP installation.

**7.**Save theapplicationhost.configfile.

**8.**Back in WebMatrix, click on**Files**, then on**Add a file to your site**:

> [![image](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/3286.image_5F00_thumb_5F00_26810151.png "image")](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/8080.image_5F00_06D22789.png)

**9.**PHP will not be listed in the types of files you can add. Instead, choose an HTML file, but name it with a .php extension:

> [![image](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/1462.image_5F00_thumb_5F00_73B0FADC.png "image")](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/2022.image_5F00_462FDB19.png)

Now you are ready to write PHP code:

[![image](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/2548.image_5F00_thumb_5F00_05215BB5.png "image")](http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-33-78-metablogapi/8080.image_5F00_4557752F.png)

That’s it for now. I’ll continue to use WebMatrix and write more about what I find, but I’m hoping this will get you started with using WebMatrix and PHP so you can chime in with your feedback (which I will make sure makes it to the development team).

Thanks.

-Brian

原文地址：[http://blogs.msdn.com/b/brian\_swan/archive/2010/07/12/creating-php-websites-with-webmatrix.aspx](http://blogs.msdn.com/b/brian_swan/archive/2010/07/12/creating-php-websites-with-webmatrix.aspx)