Creating PHP Websites with WebMatrix

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, seehttp://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. His postdescribes whatWebMatrixis 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 theWeb Application Gallery. Ruslan Yakushev followed up with a blog post that delved a bit deeper into PHP support in WebMatrix:Install PHP Applications with WebMatrix. As I read those posts (andothers), 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 theWeb Application Gallery, 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/

2.Run the Web PI and clickInstall Microsoft WebMatrixon theGetting Startedtab. Or, if you want to also install other programs, selectMicrosoft WebMatrix Betaon theWhat’s Newtab, then select other programs before proceeding.

image

3.Launch WebMatrix and click onSite From Template:

image

4.Select anEmpty Siteand provide a name for the site (I’m calling my “PHPSite”).

image

5.In a text editor, open theapplicationhost.configfile located in yourDocuments\IISExpress8\configdirectory. Replace the<fastcgi />element with the following element:

<fastCgi>
<application fullPath="C:\PHP\php-cgi.exe"
activityTimeout="600"
requestTimeout="600"
instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS"
value="10000" />
<environmentVariable name="PHPRC"
value="C:\PHP" />
</environmentVariables>
</application>
</fastCgi>

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:

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

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 onFiles, then onAdd a file to your site:

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

Now you are ready to write PHP code:

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

你可能感兴趣的:(Matrix)