Presentation on theme: "Running PHP on Windows Server 2008 and IIS 7 Rob Cameron Developer Evangelist, Communications Sector Microsoft."— Presentation transcript:
Running PHP on Windows Server 2008 and IIS 7 Rob Cameron Developer Evangelist, Communications Sector Microsoft
Session Objectives And Agenda Objectives Learn how to host existing PHP applications on IIS Learn how to take advantage of IIS7 to extend existing PHP applications with ASP.NET Agenda Running PHP applications on IIS7 Deploying and managing PHP applications on IIS7 Extending PHP applications with IIS7 Best practices
IIS6 Application Framework support Common Gateway Interface (CGI) for CGI and PHP applications Benefits Very simple to implement and use – single-threaded execution Disadvantages Poor performance due to high process creation cost Creates and passes request data to a new CGI process Waits for CGI process to produce response Shuts down CGI process
IIS6 Application Framework support Internet Server Application Programming Interface (ISAPI) Benefit of ISAPI Can be extremely fast when written correctly Disadvantage of ISAPI Must be thread-safe (many PHP extensions are not!) Requires development in C++
FastCGI in IIS7 FastCGI: the best of both CGI and ISAPI Enhancement to CGI protocol Web server creates FastCGI process for very first request Web server re-uses existing FastCGI process for subsequent requests Ships as part of IIS7, installed with the CGI feature Benefits of FastCGI for Windows OS Much faster than CGI because there is no process creation cost Much more stable than ISAPI because of single threaded execution environment Non-thread safe PHP build is recommended for FastCGI
FastCGI Handler Architecture IIS Worker Process Request queue FastCGI process pool for PHP5 php-cgi.exe FastCGI process pool for PHP4 php.exe FastCGI protocol over named pipes or TCP
Installing FastCGI and PHP on IIS7 DEMO
Deploying PHP applications on IIS7 Control IIS configuration for PHP applications via web.config Example: setting default document for PHP application Run PHP applications in the new IIS7 integrated pipeline with ASP.NET and other web applications Extend existing PHP applications with rich ASP.NET functionality Develop new.NET modules that run in the integrated pipeline to handle PHP requests the same way as the module handles requests for ASP.NET content. Example: URL Rewriter that makes “pretty” URLs for PHP and ASP.NET content.
Extending PHP in the Integrated Pipeline IIS7’s Integrated Pipeline enables ASP.NET to serve as the standard.NET extensibility mechanism for IIS7. Provides the same familiar ASP.NET APIs and features for building web applications. ASP.NET provides a rich application framework for rapid application extensions to existing PHP applications. Example: Adding Access Control to an existing PHP application…. Using PHPUsing ASP.NET Building a custom credential store and cookie-based authentication from the ground up. Rich membership service, built-in credential store providers, the forms authentication module, and a set of pre-made Login controls.
Extending Existing PHP Applications with ASP.NET in the IIS7 Integrated Pipeline DEMO
Best Practices for Running PHP on IIS7 Want to ensure that a new process is created if no processes are available to handle a request? Run one instance per CPU with a minimum of 4 instances Set maxInstances to the lowest possible number under full load without consuming 100% CP Want to make sure that the existing process is recycled periodically? Set instanceMaxRequests (number of requests to process before recycling) as high as possible without destabilizing the app PHP process’ maximum request setting (PHP_fcgi_max_requests) has to be equal or higher than the instanceMaxRequests setting.
Best Practices for Running PHP on IIS7 Want to set PHP specific environment variables in the web.config file? Use environmentVariables configuration setting to set PHP specific environment variables.
Best Practices for Running PHP on IIS7 Is your server under so much load that your clients are getting timeout responses? The FastCGI process will be terminated if it does not respond to FastCGI handler within specified time period. Set the requestTimeout (number of seconds to wait for process to handle the request) value to be higher than the activityTimeout (number of seconds to wait for any process activity) value.
FastCGI Best Practices Want to use FastCGI process security context? Application pool identity is used for FastCGI process Use fcgi.impersonate PHP setting if client impersonation is necessary Need support for FastCGI and PHP on Windows Server? Looking for support from the community? Want to ensure serviceability and patching of PHP for business critical apps? Consider Zend’s commercial offerings (Zend Core) Need FastCGI for IIS6 installations? FastCGI Extension for IIS6 is now available for download!
Summary FastCGI for IIS6 is now available for download! FastCGI radically improves the reliability and performance for existing PHP applications on both IIS6 and IIS7 The new integrated pipeline in IIS7 introduces the ability to extend existing PHP applications with ASP.NET, as well as develop managed modules that handle requests for any web application (ASP.NET, PHP, Ruby, etc.) in the request pipeline
IIS.NET: Home for IIS Community! In-depth technical articles and samples Connect with other IIS experts on blogs & forums Free advice and assistance in forums Download center with IIS solutions