Hosting PHP on IIS 7.0 Best Practices for shared hosting

15
1 Hosting PHP on IIS 7.0 Best Practices for shared hosting Microsoft® Hosting Deployment Accelerator

description

Hosting PHP on IIS 7.0 Best Practices for shared hosting. Microsoft® Hosting Deployment Accelerator. Agenda. PHP Setup FastCGI architecture Hosting guidance Multiple PHP versions Per-site PHP configuration Providing URL rewriting Managing CPU usage Summary. PHP setup steps. - PowerPoint PPT Presentation

Transcript of Hosting PHP on IIS 7.0 Best Practices for shared hosting

Page 1: Hosting PHP on IIS 7.0 Best Practices for shared hosting

1

Hosting PHP on IIS 7.0Best Practices for shared hosting

Microsoft®

Hosting Deployment Accelerator

Page 2: Hosting PHP on IIS 7.0 Best Practices for shared hosting

2

Agenda

PHP SetupFastCGI architectureHosting guidance

Multiple PHP versionsPer-site PHP configurationProviding URL rewritingManaging CPU usage

Summary

Page 3: Hosting PHP on IIS 7.0 Best Practices for shared hosting

3

PHP setup steps

Copy binaries •Use zip file with non-thread safe binaries•Alternatively - download PHP installer

Configure php.ini•fastcgi.impersonate = 1•cgi.fix_pathinfo = 1•open_basedir = “C:\Websites\”

Configure IIS•Enable CGI•Configure FastCGI handler mapping for *.php•Change FastCGI settings

Test that it works •C:\php\php-cgi.exe –info•http://localhost/phpinfo.php

Page 4: Hosting PHP on IIS 7.0 Best Practices for shared hosting

4

FastCGI process pool for PHP5

FastCGI Handler Architecture

IIS Worker Process

Read Configuration

Authenticate

Authorize

Map Request

Handle Request

Send Response

Log Request

FastCGI protocol over named pipes or TCP

FastCGI

ASP.NET

Static

Request queue

Page 5: Hosting PHP on IIS 7.0 Best Practices for shared hosting

5

App Pool #1 (user1)

Web site #1

Recommended configuration

FastCGI Process Pool

… …

App Pool #2 (user2)

Web site #2

FastCGI Process Pool

App Pool #N (userN)

Web site #N

FastCGI Process pool

Page 6: Hosting PHP on IIS 7.0 Best Practices for shared hosting

6

Recommended configuration

Configure security isolationOne app pool per web siteEnable FastCGI impersonation

Prevent failures caused by PHP recyclingset PHP_FCGI_MAX_REQUESTS >= instanceMaxRequests

For higher site density:use dynamicIdleThresholdreduce idleTimeoutreduce maxInstances (may affect performance)

Page 7: Hosting PHP on IIS 7.0 Best Practices for shared hosting

7

Enhance your PHP hosting offer

Allow customers to choose PHP version

• Support both PHP 4.X and 5.X on the same server

Provide your customers with flexibility of changing PHP configuration

• Enable hosting of PHP apps that require tweaks to php.ini

Easily enable sub-domains

• Use URL rewrite module to implement sub-domains support

Provide URL rewriting functionality

• Expose rich set of IIS tools for creating and testing of rewrite rules

Page 8: Hosting PHP on IIS 7.0 Best Practices for shared hosting

8

Multiple PHP versions

App Pool #1 (user1)

Web site #1

Process Pool for PHP 5

App Pool #2 (user2)

Web site #2

Process Pool for PHP 4

C:\PHP526\php-cgi.exe

C:\PHP447\php.exe

Page 9: Hosting PHP on IIS 7.0 Best Practices for shared hosting

10

Per-site PHP configurationConfiguring FastCGI process pool

<fastCgi> <application fullPath="C:\PHP\php-cgi.exe" arguments="-d my.website=website1"> <environmentVariables> <environmentVariable name="PHPRC" value="C:\WebSites\website1" /> </environmentVariables> </application></fastCgi>

Combination of fullPath and arguments uniquely identify FastCGI process pool definition

PHPRC environment variable contains path to the php.ini file

Page 10: Hosting PHP on IIS 7.0 Best Practices for shared hosting

11

Per-site PHP configurationConfiguring Handler Mapping

<system.webServer> <handlers accessPolicy="Read, Script"> <add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe|-d my.website=website2" resourceType="Unspecified" requireAccess="Script" /> </handlers></system.webServer>

Reference FastCGI process pool by concatenating [fullPath]|[arguments]

Page 11: Hosting PHP on IIS 7.0 Best Practices for shared hosting

12

Providing URL rewriting

Page 12: Hosting PHP on IIS 7.0 Best Practices for shared hosting

13

Manage CPU utilizationWindows Server Resource Manager (WSRM)

Available in all SKU’s of WS2008Ensures that process gets *at least* the configured CPU percentageKicks in only if overall CPU load is more than 70%

IIS team tested with 4000 web sites

Page 13: Hosting PHP on IIS 7.0 Best Practices for shared hosting

14

Using WSRM

Page 14: Hosting PHP on IIS 7.0 Best Practices for shared hosting

15

Best practices summary

Follow IIS 7.0 security isolation guidelinesLeverage FastCGI/IIS features to enhance hosting offer:

Multiple PHP versionsPer-site PHP configurationURL rewriting

Use WSRM to manage w3wp.exe and php-cgi.exe CPU utilization

More information at http://learn.iis.net/page.aspx/208/fastcgi-with-php

Page 15: Hosting PHP on IIS 7.0 Best Practices for shared hosting

16

Q & A