<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://drewby.spaces.live.com/mmm2008-05-17_13.22/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fdrewby.spaces.live.com%2fcategory%2fPHP%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Drewby: PHP</title><description /><link>http://drewby.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catPHP</link><language>en-US</language><pubDate>Thu, 03 Jul 2008 21:09:05 GMT</pubDate><lastBuildDate>Thu, 03 Jul 2008 21:09:05 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://drewby.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>9197700824605289741</live:id><live:alias>drewby</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Managing PHP and PHP Applications in IIS7</title><link>http://drewby.spaces.live.com/Blog/cns!7FA4CC2B20EA6D0D!727.entry</link><description>&lt;p&gt;Last week I spoke at &lt;a href="http://www.phpconf.ru/"&gt;PHPConf&lt;/a&gt; in Moscow, Russia. I really enjoyed the experience - both the conference, and visiting Moscow. &lt;a href="http://drewby.spaces.live.com/PersonalSpace.aspx?_c11_PhotoAlbum_spaHandler=TWljcm9zb2Z0LlNwYWNlcy5XZWIuUGFydHMuUGhvdG9BbGJ1bS5GdWxsTW9kZUNvbnRyb2xsZXI$&amp;amp;_c11_PhotoAlbum_spaFolderID=cns!7FA4CC2B20EA6D0D!697&amp;amp;_c=PhotoAlbum"&gt;You can view the pictures here.&lt;/a&gt; I was asked by a couple people to summarize the presentation, which was about using Internet Information Server 7 to host PHP applications.  &lt;p&gt;There are five main advantages to running PHP in IIS7: Configuration, Security, Extensibility, Management and Troubleshooting. &lt;h2&gt;Configuration&lt;/h2&gt; &lt;p&gt;IIS7 comes with a completely new configuration system that's based on a central file called applicationHost.config. This file is a well-organized, schema-based XML file that contains every configuration setting possible for IIS7.  &lt;p&gt;There are times when configuring certain settings would be best accomplished at the web directory level. So the configuration elements in applicationHost.config can also be distributed to local web.config files stored in the directory of the web application. &lt;p&gt;For PHP developers that means they can deploy the configuration settings for their application along with the source files. For example, a PHP developer can configure the default document inside a local web.config file and then copy that web.config file to the server along with their application. That's a simple example, but it extends to other configuration settings such as handlers, modules, authentication, etc.  &lt;p&gt;A server administrator can choose which settings get configured centrally and which ones can be delegated to local web.config files. It all adds up to a lot of flexibility in how a server and it's applications get configured. &lt;p&gt;Here are three great exercises you can go through to understand configuration and delegation a little better: &lt;p&gt;&lt;a title="Delegating permissions in IIS Manager"&gt;&lt;/a&gt;&lt;a title="How to Use Configuration Delegation in IIS7" href="http://www.iis.net/articles/view.aspx/IIS7/Managing-IIS7/Delegation-in-IIS7/Delegating-Permission-in-Config/How-to-Use-Configuration-Delegation-in-IIS7"&gt;How to Use Configuration Delegation in IIS7&lt;/a&gt; &lt;p&gt;&lt;a title="How to Use Locking in IIS7 Configuration" href="http://www.iis.net/articles/view.aspx/IIS7/Managing-IIS7/Delegation-in-IIS7/Delegating-Permission-in-Config/How-to-Use-Locking-in-IIS7-Configuration"&gt;How to Use Locking in IIS7 Configuration&lt;/a&gt; &lt;p&gt;&lt;a title="Understanding IIS7 Configuration Delegation" href="http://www.iis.net/articles/view.aspx/IIS7/Managing-IIS7/Delegation-in-IIS7/Delegating-Permission-in-Config/Understanding-IIS7-Configuration-Delegation"&gt;Understanding IIS7 Configuration Delegation&lt;/a&gt; &lt;h2&gt;Security&lt;/h2&gt; &lt;p&gt;The IIS team did a tremendous job in making IIS6 a secure platform to host web applications. However, you will be blown away with the completely new modular architecture for IIS7 and what it means for security. &lt;p&gt;Every piece of functionality in IIS7 is a module that can be added or removed. An interesting experiment you can walk thru is to remove every module from IIS7 and then make a request. The result is that the request gets denied, because the anonymous authentication module is removed. However, the server is unable to serve an error message because that module is also removed.  &lt;p&gt;Here's the response: &lt;p&gt;&lt;font face="Courier New"&gt;HTTP/1.1 401 Unauthorized&lt;br&gt;Server: Microsoft-IIS/7.0&lt;br&gt;Date: Thu, 31 May 2007 21:11:33 GMT&lt;br&gt;Content-Length: 0&lt;/font&gt;  &lt;p&gt;If you add the anonymous authentication module back in, then you receive a 404 result because the static file module is not configured. Once you add this module back into the configuration, you now have a static file server and nothing else. &lt;p&gt;The point is that you can add only the modules you need for your scenario, creating the IIS7 server that is right for you. This means that you have the bare minimum surface area for attackers to target. You only need to patch your server when an update touches one of the modules you have configured. &lt;p&gt;A bare minimum PHP configuration could include Anonymous Authentication, Static Files (for images) and the FastCGI PHP Handler. You'll probably also want the Custom Error Module to show friendly 404 errors, etc. &lt;p&gt;Try it with one of these exercises: &lt;p&gt;&lt;a title="How to Build a Custom, Reduced Footprint Web Server" href="http://www.iis.net/articles/view.aspx/IIS7/Deploy-an-IIS7-Server/Installing-IIS7/Build-a-Custom-IIS7-Server"&gt;How to Build a Custom, Reduced Footprint Web Server&lt;/a&gt; &lt;h2&gt;Extensibility&lt;/h2&gt; &lt;p&gt;This is where I think it gets really cool. One of the things I've always liked about PHP, is the practicality of developing on the platform. When creating a website, you'll often find there are already applications, components, etc that PHP developers around the world have made freely available. You can get up and running in a short period of time. &lt;p&gt;Although I don't believe the ASP.NET community has as many complete applications, there are still a plethora of ASP.NET components freely available to help in website development. In the past, these two worlds have been mutually exclusive.  &lt;p&gt;In version 6 and earlier of IIS, the only way to extend the web server was by writing C++ code to create ISAPI extensions and filters. ASP.NET developers could create modules and handlers in C# or VB.NET, but these only applied to ASPX pages or other ASP.NET objects. For example, forms authentication is implemented as an HTTP module. We can use forms authentication to protect ASPX pages, but static HTML files and images in the same website would not be protected. &lt;p&gt;In IIS7, there is a new unified pipeline that allows managed (C#, VB.NET) and unmanaged (C++) modules to work side-by-side and apply to all requests. For the PHP developer, that means your options have just expanded. Not only can you make use of all the existing PHP code available in the world, but you can also make use of ASP.NET code written to extend IIS.  &lt;p&gt;As an example, I did the following during my presentation at PHPConf: &lt;ol&gt; &lt;li&gt;Configured &lt;a href="http://g.msn.com/9SE/1?http://qdig.sourceforge.net/&amp;amp;&amp;amp;DI=6244&amp;amp;IG=838c9cf439a24e84b04be2c4e00e8407&amp;amp;POS=1&amp;amp;CM=WPU&amp;amp;CE=1&amp;amp;CS=AWP&amp;amp;SR=1"&gt;QDIG, a PHP image gallery application&lt;/a&gt;.  &lt;li&gt;Added forms authentication by updating the web.config file and adding a Login.aspx and Register.aspx to the website. Of course, the membership database is generated by ASP.NET and the two ASPX files required only one element each.  &lt;li&gt;Added a URL rewriting module to change the format of URLs and map those into the query string variables for QDIG. I used &lt;a href="http://www.urlrewriting.net/en/Default.aspx"&gt;the module available here&lt;/a&gt; as a compiled assembly added to the &lt;em&gt;bin&lt;/em&gt; directory in my QDIG application folder. There are a bunch of similar modules on the web. &lt;li&gt;Added the &lt;a href="http://www.iis.net/articles/view.aspx/IIS7/Extending-IIS7/Getting-Started/An-End-to-End-Extensibility-Example-for-IIS7-Devel"&gt;ImageCopyright handler described in this article&lt;/a&gt;. I added this handler in source code form to the &lt;em&gt;App_Code&lt;/em&gt; directory. This added a copyright message to all the photos in my QDIG album.&lt;/ol&gt; &lt;p&gt;Combined all together, I thought this made a very compelling example of using IIS7, ASP.NET and PHP together to &lt;em&gt;quickly&lt;/em&gt; configure the functionality required for a complete application. &lt;p&gt;In addition to extending the IIS7 request pipeline, developers can also extend: &lt;ul&gt; &lt;li&gt;&lt;strong&gt;Configuration system&lt;/strong&gt; - add new schema to the IIS7 configuration files. Not only will IIS7 be able to understand the new sections, but the command line tool will now be able to manipulate your new config sections.  &lt;li&gt;&lt;strong&gt;IIS Management Tool&lt;/strong&gt; - You can add new pages, dialogues and tree view items for the GUI management tool.  &lt;li&gt;&lt;strong&gt;Diagnostics&lt;/strong&gt; - there is a great diagnostics system in IIS7 that I'll discuss later which you can also extend, adding your own diagnostic information for your application.&lt;/ul&gt; &lt;p&gt;&lt;a title="An End to End Extensibility Example for IIS7 Devel" href="http://www.iis.net/articles/view.aspx/IIS7/Extending-IIS7/Getting-Started/An-End-to-End-Extensibility-Example-for-IIS7-Devel"&gt;An End to End Extensibility Example for IIS7 Developers&lt;/a&gt; &lt;h2&gt;Management&lt;/h2&gt; &lt;p&gt;The new IIS Manager is completely rewritten and organized in a much better way than previous versions. Not only can you manipulate IIS configuration using this GUI, but you can also manage ASP.NET settings including the users and roles in your membership store. And with third parties having the ability to extend the tool, you'll be able to manage many application settings from within this interface. &lt;p&gt;The IIS Manager leverages the HTTP protocol for remote administration which makes it a lot easier to use for administering hosted servers or servers behind a firewall. &lt;p&gt;In addition to the GUI management tool, there is also a new command-line utility called APPCMD. This tool can do everything the IIS Manager can accomplish, so you have complete control over your server from a console window. &lt;p&gt;&lt;a title="Getting Started with IIS Manager" href="http://www.iis.net/articles/view.aspx/IIS7/Use-IIS7-Administration-Tools/IIS-Manager-Administration-Tool/Getting-Started-with-IIS-Manager"&gt;Getting Started with IIS Manager&lt;/a&gt; &lt;p&gt;&lt;a title="Remote Administration for IIS Manager" href="http://www.iis.net/articles/view.aspx/IIS7/Use-IIS7-Administration-Tools/IIS-Manager-Administration-Tool/Remote-Administration-for-IIS-Manager"&gt;Remote Administration for IIS Manager&lt;/a&gt; &lt;p&gt;&lt;a title="Getting Started with AppCmd exe" href="http://www.iis.net/articles/view.aspx/IIS7/Use-IIS7-Administration-Tools/Using-the-Command-Line/Getting-Started-with-AppCmd-exe"&gt;Getting Started with AppCmd exe&lt;/a&gt; &lt;h2&gt;Troubleshooting &amp;amp; Diagnostics&lt;/h2&gt; &lt;p&gt;The final area that is a huge improvement in IIS for PHP developers is in troubleshooting and diagnostics. There is nothing more frustrating than when performance degrades on your website and you can't figure out the reason. IIS7 gives you some great tools for diagnosing those issues. &lt;p&gt;The first one is new in-process state information that can be accessed thru IIS Manager, APPCMD, or programmatically from code. This gives you the ability to view current application domains, executing requests, process IDs for application pools, etc. You can do queries on the server to give you information like all of the requests that are currently running and taking longer than X seconds. &lt;p&gt;The second tool is Failed Request Tracing. When this feature is enabled, IIS collects vital information about every request in a buffer. If the request fails or meets some other condition that you determine, then the buffer is saved to disk so you can analyze the data. The data contains a list of every module that executed during the request and how much time the module took. It also contains overall information about the request critical to determining the cause of an issue in the application or IIS. &lt;p&gt;&lt;a title="How to Access IIS7 RSCA Data" href="http://www.iis.net/articles/view.aspx/IIS7/Managing-IIS7/Diagnostics-in-IIS7/Inside-RSCA/How-to-Access-IIS7-RSCA-Data"&gt;How to Access IIS7 RSCA Data&lt;/a&gt; &lt;p&gt;&lt;a title="Troubleshooting Failed Requests using Tracing in I" href="http://www.iis.net/articles/view.aspx/IIS7/Managing-IIS7/Diagnostics-in-IIS7/Using-Failed-Request-Tracing/Troubleshooting-Failed-Requests-using-Tracing-in-I"&gt;Troubleshooting Failed Requests using Tracing in IIS7&lt;/a&gt; &lt;h2&gt;FastCGI and PHP&lt;/h2&gt; &lt;p&gt;Last year, Microsoft announced a collaboration with Zend to make improvements to the hosting experience for PHP applications on Windows. On the Microsoft side, we've been working on a &lt;a href="http://www.iis.net/default.aspx?tabid=1000051"&gt;FastCGI module&lt;/a&gt; to resolve the issues encountered when hosting PHP as an ISAPI or CGI module on Windows. You'll be able to achieve much better performance using this module. It is available for &lt;a href="http://www.iis.net/default.aspx?tabid=1000053"&gt;IIS5 on Windows XP&lt;/a&gt;, &lt;a href="http://www.iis.net/default.aspx?tabid=1000053"&gt;IIS6 on Windows 2003&lt;/a&gt; and &lt;a href="http://www.iis.net/default.aspx?tabid=1000052"&gt;IIS7 on Windows Vista&lt;/a&gt;. It will also be included as a component in IIS7 on Windows 2008. &lt;p&gt;On the Zend side of the collaboration, they have been working on fixing some of the issues with the PHP engine itself when running on Windows. They've really made a lot of progress. &lt;a href="http://www.php.net/downloads.php"&gt;Make sure you are using the latest builds of PHP.&lt;/a&gt; You will see a performance improvement. &lt;p&gt;&lt;a title="Using FastCGI to host PHP applications on IIS7" href="http://www.iis.net/articles/view.aspx/IIS7/Hosting-Web-Applications/PHP/Using-FastCGI-to-host-PHP-applications-on-IIS7"&gt;Using FastCGI to host PHP applications on IIS7&lt;/a&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=9197700824605289741&amp;page=RSS%3a+Managing+PHP+and+PHP+Applications+in+IIS7&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=drewby.spaces.live.com&amp;amp;GT1=drewby"&gt;</description><comments>http://drewby.spaces.live.com/Blog/cns!7FA4CC2B20EA6D0D!727.entry#comment</comments><guid isPermaLink="true">http://drewby.spaces.live.com/Blog/cns!7FA4CC2B20EA6D0D!727.entry</guid><pubDate>Fri, 01 Jun 2007 21:24:54 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://drewby.spaces.live.com/blog/cns!7FA4CC2B20EA6D0D!727/comments/feed.rss</wfw:commentRss><wfw:comment>http://drewby.spaces.live.com/Blog/cns!7FA4CC2B20EA6D0D!727.entry#comment</wfw:comment><dcterms:modified>2007-06-01T21:28:24Z</dcterms:modified></item></channel></rss>