You are on page 1of 66

Interoperability Software PHP IIS7 Windows Web Server

seree@buu.ac.th

Agenda
PHP on Windows IIS 7.0 Core Architecture FastCGI on IIS 7.0 Best practices and patterns Demo Web Application (e-Office)

PHP on Windows
Whats the difference between PHP on Windows and Linux Why I run PHP on Windows !

Why you might Run PHP on Windows


The PHP Ecosystem
Applications, Applications, Applications Open source designs Loose and Wild The PHP community contributes to a variety of defacto standard facilities to connect everything Zend and the PHP community are invested in Windows Specific PHP technology.

Some Favorite PHP Applications


PHP-Nuke PostNuke RunCMS Mambo Xoops MyPHPAdmin

PHPBB2

VBulletin

VBPortal

cPanel

Drupal

e107

MD-Pro

MyPHPNuke

PHPWebSite

TikiWiki

Typo3

Xaraya

b2Evolution

bBlog

Serendipity

WordPress

TextPattern

OSCommerce

OSCNuke

Zen Cart

eGroupWare

phpGroupWare

Site@School

ATutor

Moodle

Segue

Coppermine

QwikiWikki

SugarCRM

WebCalendar

Potential Advantages to running PHP on Windows.


Windows Ecosystem
Over 600,000 partners in the Microsoft Ecosystem. Microsoft makes MUCH more than Windows Microsoft is making huge investments interoperability standards and technologies. (WSI, etc.) Microsoft provides . a complete turn-key infrastructure . Individual best-of-breed applications for you to choose from

FUTURE TECHNOLOGIES

Software Options from Microsoft


MS Access MS Outlook BizTalk SQL Server MS LCS Identity Integration Server

MS Excel

PowerPoint

SharePoint

SQL RS

Business Manager

ISA Server

MS FrontPage

MS Project

MS CMS

SQL AS

Virtual Earth

Data Analyzer

MS InfoPath

Small Business Accounting

Exchange Server

SQL NS

Messenger

MS Mobile

Live Meeting

MS Visio

Commerce Server

Project Server

MapPoint

Tablet PC

MS OneNote

MS Word

MS CRM

MOM

App Center

MS Starter Kits

More Software Options from Microsoft


Active Directory

IIS 6/7

Axapta

Navision

Info Bridge

Media Center

ADAM

MSMQ

Great Plains

Retail Management

WSH

Info Card

Authorization Manager

Windows Server 2003

Small Business Manager

Windows Unix Services

DirectX

WinFX

Operations Manager

Windows Mobile

MS Solomon

VBA / VSA

ActiveX

Windows Workflow

MS Enterprise Reporting

XML-WS WSE

Application Center

MSN Search

Hosted Controls

Presentation Foundation (Avalon)

Windows Embedded

Windows Media Server

System Management Server

Windows Index Server

Host Integration Server

Vista Longhorn

PHP on Windows
PHP Developers work on Windows machines anyway. PHP is PHP is PHP. Zend offers the Winabler. Other 3rd parties offer.
Phalanger = Managed Code PHP http://www.php-compiler.net/

Zends Windows Work Continues

PHP On Windows
Whats the problem anyway.
CGI on Windows ? The PHP ISAPI Extension Will it get fixed ?

PHP on Windows
FASTCGI ! PHP on IIS 6
PHP Versions. Why choose ?

PHP on IIS 7
New application context ?

IIS6 Architecture Refresher


Web garden (w3wp.exe)
Worker Process Worker Process Worker Process ISAPI Extensions ISAPI Extensions ISAPI Extensions ISAPI Filters ISAPI Filters ISAPI Filters

Application Pool (w3wp.exe)


Worker Process ISAPI Extensions ISAPI Filters Worker Process ISAPI Extensions ISAPI Filters

Inetinfo.exe Lsass.exe Windows Authentication SSL metabase NNTP Service IIS Admin Service

Svchost.exe

FTP Service

SMTP Service

WWW Service (w3svc)

User Kernel

Winsock HTTP.SYS TCPIP.SYS

HTTPAPI

IIS7 Architecture Overview


Web garden (w3wp.exe) Worker Process Worker Process Worker Process ISAPI Extensions ISAPI Extensions Managed Mods ISAPI Filters ISAPI Filters ISAPI Extensions ISAPI Filters

Application Pool (w3wp.exe)


Worker Process Managed Mods ISAPI Extensions ISAPI Filters Worker Process Managed Mods ISAPI Extensions ISAPI Filters Svchost.exe

Inetinfo.exe Lsass.exe Windows Authentication SSL metabase NNTP Service IIS Admin Service

WAS FTP Service Configuration (applicationhost.co nfig)

SMTP Service

WWW Service (w3svc)

User Kernel

Winsock

HTTPAPI HTTP.SYS TCPIP.SYS

IIS6 Request flow refresher


w3wp.exe iiscore
handlers

aspnet_isapi.dll
static file ISAPI exts
IHttpModule Events url map begin req authc req authz req

cgi

Server is monolithic: cant extend core features cant remove core features cant add features Feature duplication between IIS and ASP.NET.

determine handler logging Svchost.exe custom errors compression authentication


ISAPI Filter Notifications

resolve cache
handler map handler exec

end req
update req cache rel req state

Features limited due to position in pipeline. ASP.NET functionality not applied to IIS content types.

w3svc

url map

authc req

log

IHttpHandlers

Pre-proc headers End net session

Trace.axd

PageHandler

http.sys

IIS7 Architecture
W3wp.exe
Native or Managed Handlers

Native iiscore

Handler static file isapi ext


handlers

Managed IHttpHandler aspnet_isapi *.aspx IHttpModule Events trace.axd


url map

Unified request processing pipeline. All services provided by selfcontained modules Modules can be managed or native All services can apply to all requests

static Isapi Integrated pipeline cgi begin req exts end Native file IHttpModule authc req log Module Determine handler other other
native modules update cache release state execute handler authz req managed modules

Svchost.exe

Isapi filter notifications

resolve cache

end req
update req cache rel req state

url map

log

handler map pre-execute handler acquire state handler exec

WAS w3svc

basic auth
authc req

map End net session handler resolve cache authorize

url authz mgr

digest auth

role IHttpHandlers
Trace.axd

windows auth

Pre-proc headers

authenticate
begin

forms *.aspx auth


User Kernel

http.sys Tcpip.sys

A full description of all IIS7 modules is covered in the following tables, they have been broken down in to groups based on functionality:
Caching Modules Compression Modules Content Modules Authentication Modules Security Modules Logging & Error Modules Diagnostics Modules Development Modules IIS 7.0 Managed Modules

Development technologies offered as to execute code from that platform Implements Managed Interfaces, etc.
Module Name IsapiModule IsapiFilterModule CgiModule FastCgiModule Description Implements ISAPI Extension Server Functionality Implements ISAPI filter functionality Resource Location Inetsrv\isapi.dll Inetsrv\filter.dll

Executes CGI processes to build response Inetsrv\cgi.dll output. Enables Fast CGI application frameworks like PHP be hosted on the IIS web server. Implements configuration validation, e.g. if an application runs in integrated mode but has handlers or modules declared in the system.web section. Connects the IIS core pipeline with the ASP.NET runtime and bridge between native and managed code in IIS 7.0 inetsrv\iisfcgi.dll

ConfigurationValid ationModule

inetsrv\validcfg.dll

ManagedEngine

..\Framework\v2.0.50727\webengine.dll

New Modular Architecture


The integrated pipeline
Native Managed
Custom

Managed

- or -

ASP.NET

Static

Compress

Cache

Logging

Anon

Basic

FastCGI

ASP

Errors

ISAPI

Tracing

Forms

UrlAuth

Integrated pipeline
Unified request processing pipeline for both native and managed (ASP.NET) modules
All modules can provide services for all content types.
You can use ASP.NET forms authentication and url authorization to protect all content on the server You can develop an ASP.NET module to append custom headers to static file requests.

Duplicate features unified


You can configure authorization, caching, and custom errors in one place.

Managed modules have full ordering flexibility


Managed modules can be intermixed with native modules as desired

IIS7 Modularity
Publishing Security
AnonymousAuthentication BasicAuthentication DigestAuthentication WindowsAuthentication UrlAuthorization CertificateMapping ADCertificateMapping RequestFiltering IPRestriction CGI FastCGI ServerSideIncludes ASP ASP.Net ODBCLogging LoggingLibraries RequestMonitor HttpTracing

Application Development
.NET Extensibility ISAPIFilter ISAPIExtension

Health and Diagnostics


HttpLogging

FTPServer FTP Management WebDavModule

Performance
StaticCompression DynamicCompression

CustomLogging

Management
Management Console Management Scripting

Core HTTP Server Components


DirBrowsing HttpRedirect DefaultDoc CustomErrors StaticFile

Mgmt Service (WMSVC) IIS6 Config (Metabase) IIS6 WMI Provider

Process Model (Windows Process Activation Service)


ProcessModel .Net Environment Configuration API

IIS6Scripting IIS6 Management Snap-in

A History of PHP on IIS

Invokes a process for each request. Advantages Easy to Configure Stable Execution Disadvantages Slow due to I/O Overhead of Process Creation

Loaded as extension in process. Advantages Better Performance Disadvantages Many PHP Applications are not Thread-Safe

Extension to CGI allowing reuse of a process. Advantages Easy to Configure Faster than CGI More stable than PHP on ISAPI Can run nonthread-safe versions of PHP

FastCGI Design Goals


What is FastCGI :
A language and server independent, scalable, open extension to CGI that provides high performance and persistence A protocol for data interchange between a web server and a FastCGI application The set of libraries that implement the protocol

Developed by Open Market in 96 as open solution (www.fastcgi.com) Design goals:


Speed! Eliminate CGIs weaknesses
Scalable Persistent

Build on CGIs strengths


Simple, Open Standard with an easy migration path Server, Language, & OS independent Server Isolation

FastCGI Handle Architecture


FastCGI process pool for PHP5
FastCGI protocol over named pipes or TCP

php-cgi.exe

FastCGI process pool for PHP4

Request queue php.exe

FastCGI Handler
1 : Receiving requests in IIS WP 2 : Queieing requests 3 : Dispacthing and receiving response from FastCGI process 4 : Creating one or more FastCGI App Process

FastCGI Handler
Mapping the FastCGI handler to process requests Processing all URLs in a directory Response buffering 64 bit support Process Management
Create configured FastCGI application processes when needed. Maintain a connection with each FastCGI application process during its lifetime Monitor health of FastCGI application processes Periodically recycle FastCGI processes Detect when FastCGI processes exited / crashed, and recover gracefully Terminate FastCGI processes

Queuing and request dispatching Security model

FastCGI Protocol Support


Initialization Request processing FastCGI Roles Error handling
Errors during FastCGI handler initialization Errors during application initialization Request processing errors Rapid Failure Protection

FastCGI Roles
Responder
The fundamental FastCGI role Functionally identical to CGI Supported by all FastCGI capable servers

Authorizer
Provides a means of controlling access to a site, a page, or something in between Typically, this involves some form of authentication, but this isnt required It has server dependent significance

Filter
Allows processing of a file before it is sent Intended to support: Format conversions Dynamic documents (embedded code) Applying templates: e.g. headers, footers, backgrounds Conceptually this could support dynamic content chaining, but without server support has limited utility

FastCGI for IIS6


Same FastCGI functionality as in IIS7, available as a separate download for IIS6 from the Microsoft download center
http://www.iis.net/downloads/default.aspx?tabid=34&g= 6&i=1521 Fully supported by Microsoft

Walk-throughs demonstrating how to run popular PHP applications on Windows Server


See http://www.iis.net/php

Close collaboration with Zend Technologies


Improvements in PHP engine for IIS with contributions and collaboration back to PHP Community Zend Core Available for Commercially Supported PHP

FastCGI in IIS6 and IIS7


FastCGI in IIS6 Available today on Download Center Delivered as a separate download for Windows Server 2003. FastCGI ISAPI extension Resources, forums, and reference material available on IIS.NET Configured via fcgiext.ini FastCGI in IIS7 Available with Windows Server 2008 and Vista SP1 Delivered as part of IIS7. Users must install the CGI feature in IIS to enable FastCGI. Native IIS7 module Product help documentation, as well as resources on IIS.NET. Configured via the new XML-based configuration system in IIS7.

Fully supported by Microsoft Supports PHP and other FastCGI frameworks

Advantages of PHP on IIS7


Modular architecture for reduced attack surface XML-based configuration system Remote management capability

Advanced diagnostics

Integration with WMS and Media Pack

Ability to extend IIS7 using managed code

PHP users who deployed to Apache in the past will be more comfortable with IIS7 than IIS6 due to the new configuration system and modular architecture.

New Configuration System


Say goodbye to the metabase

Configuration stored in XML files validated by a schema.


Schema
Schema describes configuration settings for IIS, ASP.NET and 3rd party applications.

applicationHost.config

Central configuration file for the server contains system wide configuration settings.

web.config

web.config

Distributed configuration files contain overrides and local site and application settings.

New IIS Manager

Easy navigation to server, sites and applications

Tasks organized by areas and features

Common actions related to navigation context

Leveraging the Platform


Rich functionality in IIS7
Included modules such as Membership Add-on modules from http://IIS.net

SQL Server 2005 Driver for PHP Other Windows Applications


Active Directory Exchange SharePoint Office

SQL Server 2005 Driver for PHP


Goal: Provide robust, scalable, and reliable SQL Server connectivity for PHP developers targeting the Windows platform Enterprise abilities to PHP/SQL Server Devs.
Reliability Scalability Maintainability

Base the PHP driver's API on existing data patterns


For more info, see the team blog http://blogs.msdn.com/sqlphp

Web application

e-Office

demo

PHP IIS7 MySQL windows IIS7

(e Office) Open Source

Open Source

PHP IIS7 Module Fast CGI server manager Role Web Server Add Role Service

CGI Next

Install

Install CGI

Module Fast CGI Module IIS Manager Handler Mappings

Add Module Mapping

Module Mapping Request Path : *.php Module : FastCGIModule Executable : php-cgi.exe Name : php

FastCGI

PHP

my.ini MySQL code


lower_case_table_names=2

Restart service MySQL


lower_case_table_names=2

Web Server PHP MySQL e-Office Internet Explorer phpMyAdmin


eoffice

eoffice Home Directory Home Directory E:\


Home Directory

Internet Explorer eoffice eoffice

config.php db.php Database e-Office

IIS7 FastCGI
Fast CGI + Caching
Fast CGI

Reference
FastCGI on IIS 7.0 by Risman Adnan PHP on Microsoft 7.0 by Risman Adnan
http://geeks.netindonesia.net/blogs/risman

PHP and the Microsoft Platform by Joe Stagner http://www.JoeOn.net

path Encode file Unicode MySQL charset utf-8

You might also like