www.it-ebooks.info www.it-ebooks.info Integrating PHP with Windows ® Arno Hollosi www.it-ebooks.info Published with the authorization of Microsoft Corporation by: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, California 95472 Copyright © 2011 by O’Reilly Verlag GmbH All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. ISBN: 978-0-7356-4791-6 1 2 3 4 5 6 7 8 9 M 6 5 4 3 2 1 Printed and bound in the United States of America. Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at mspinput@microsoft.com. Please tell us what you think of this book at http://www.microsoft.com/learning/booksurvey. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/ IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are ctitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, O’Reilly Media, Inc., Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Russell Jones Holly Bauer Octal Publishing, Inc. Lars Dekenno Bob Russell Julie Hawks Twist Creative • Seattle Karen Montgomery Robert Romano FH CAMPUS 02/Peter Melbinger www.it-ebooks.info Contents at a Glance Part I Setting Up the Work Environment 3 IIS Architecture 19 Conguring IIS 41 Conguring PHP 61 Security 85 Caching 117 URL Rewrite 137 Error Messages and Error Search 185 Part II Setting Up SQL Server 201 Databases and Tables 225 Working with SQL Server 253 PHP and SQL Server 279 Advanced Database Functions 319 Users and Permissions 343 Part III Setting Up Active Directory 365 LDAP Basics 389 Searching in Active Directory 413 Writing in Active Directory 451 www.it-ebooks.info Contents at a Glance Part IV Setting Up Exchange Server 479 Exchange Web Services 491 Email and Exchange Web Services Basics 509 Contacts and Search 539 Calendar and Impersonation 559 www.it-ebooks.info Table of Contents Introduction xxi Part I Setting Up the Work Environment 3 Setting Up IIS 4 Installing IIS by Using the Server Manager 4 Installing from the Command Line 6 Setting Up PHP 6 Installing PHP 6 Available PHP Modules 8 Conguring PHP in IIS 8 Conguring PHP by Using the IIS Manager 9 Conguring PHP from the Command Line 11 Installing by Using the Web Platform Installer 12 Setting Up the Web PI 12 Setting Up IIS and PHP 13 Checking Your PHP Installation 14 Backing Up Your Conguration 14 A First Sample Application 15 Remote Access 16 Summary 18 IIS Architecture 19 Sites 19 Setting Up a New Site 20 Adding Additional Bindings 24 Managing the Website 26 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you To participate in a brief online survey, please visit: microsoftcom/learning/booksurvey www.it-ebooks.info Table of Contents Applications 27 Paths and Folders 27 Setting Up a New Application 28 Changing Application Settings 29 Virtual Directories 30 Setting Up a Virtual Directory by Using IIS Manager 30 Setting Up a Virtual Directory from the Command Line 31 HTTP Request Flow 31 Request Flow Overview 32 Application Process Flow 33 Modules 34 Application Pools 35 Setting Up Application Pools by Using IIS Manager 35 Setting Up Application Pools from the Command Line 35 Application Pool Identity 36 FastCGI 38 FastCGI vs CGI 38 FastCGI vs ISAPI 40 Summary 40 Conguring IIS 41 Conguration Files 42 Global Conguration 42 Distributed Conguration 42 Conguration Structure 43 Sections and Section Groups 44 Elements and Conguration Listings 44 Moving and Binding Sections 45 The Conguration Editor 45 Schema and congSections 47 Conguring Paths by Using location 47 Conguring by Using IIS Manager 48 Conguring from the Command Line 49 Sites, Applications, and Directories 49 Sites 50 Applications 52 Virtual Directories 53 www.it-ebooks.info Table of Contents Locking the Conguration 53 Locking with congSections 54 Locking and Unlocking with location 54 Specifying Rights for Individual Settings 56 Locking and Unlocking by Using IIS Manager 58 Summary 60 Conguring PHP 61 Installing PHP Manager 61 Conguring PHP 63 Recognizing Conguration Changes 63 Path and Host-Dependent Conguration in phpini 65 Conguring by Using userini 66 Specifying the Default Document 69 Specifying the Default Document by Using the IIS Manager 69 Specifying from the Command Line 70 Dening Directly in the Conguration 71 Request Limits 71 Conguring by Using the IIS Manager 72 Conguring from the Command Line 73 Conguring Directly in the Conguration File 73 Time Limits for Request Processing 74 PHP Limits 74 FastCGI Limits 74 Session Storage and Temporary Files 75 Setting Up PHP Syntax Highlighting 76 Conguring Syntax Highlighting by Using the IIS Manager 76 Conguring from the Command Line 78 Setting Up Different PHP Versions 78 Installing a New PHP Version 78 Conguring by Using the PHP Manager 79 Conguring the Handler Assignment 79 Conguring the FastCGI Application 80 Testing 81 Setting Up Different PHP Congurations 83 Summary 83 www.it-ebooks.info Table of Contents Security 85 Structuring the Application 86 Root Folder or Virtual Directory 87 Specifying the Executable Files 89 PHP Conguration 90 User Authentication 92 Installing the Required Role Services 93 Setting Up User Authentication by Using IIS Manager 93 Setting Up User Authentication from the Command Line 94 Windows Authentication and Host Names 94 Retrieving the Authentication in PHP 95 Identity and Access Rights 96 Identity of the Application Pool 96 Path Logon Information 97 Specifying the Identity of the Anonymous User 97 Securing the PHP Application 98 Authorization Rules 98 Installing the Required Role Services 99 Dening the Rules by Using IIS Manager 99 Dening the Rules from the Command Line 100 Request Filter 101 Dening General Settings 102 Filtering File Name Extensions 106 Filtering with Rules 107 Encrypted Connections (HTTPS) 109 Creating Keys and Certicates 109 Setting up an Encrypted Connection 110 Authentication with Client Certicates 114 Summary 115 Caching 117 Caching in the Web 117 Caching for a Limited Time 118 Mutable Contents 120 Caching Conditions 122 Specifying the Headers with IIS 123 www.it-ebooks.info [...]... supporting PHP in its own products, and is now explicitly incorporating PHP into its development strategy, thus promoting interoperability with the Windows platform Thanks to the recent efforts by the Windows PHP team, including Pierre Joye, Ruslan Yakushev, and others, the combination of IIS and PHP is now faster, more stable, more secure, and easier to manage than ever These efforts—FastCGI, WinCache, PHP. .. new drivers for SQL Server, the integration with Microsoft’s Web Platform Installer (Web PI), as well as development aids for Windows Azure, Virtual Earth, Webslices, Silverlight, and SQL Server (just to name a few)—make PHP development on Windows an enjoyable and productive experience Combined with the ever-improving interoperability of Microsoft’s products, PHP is ready for just about every task in... Introduction PHP has changed the world: no other language has influenced and spurred web development so strongly From simple home pages to social software and business applications to the largest global websites, PHP has played a leading role for years Simultaneously, Microsoft and its Windows operating system has made computers available to all households Along with Internet Information Services (IIS) for Windows. .. the PHP_ sample_code.zip file www.it-ebooks.info xxvi Introduction Using the Code Samples The folder created by extracting the zip file contains two subfolders ■ Listings This folder contains all of the listings sorted by chapter, as they appear in the book The listings are UTF-8 encoded, without a byte-order mark (BOM) at the beginning The filename suffix indicates the content: * .php PHP script or PHP. .. tool that ships with Windows Server 2008 for managing optional Windows features It replaces the older sysocmgr.exe tool Important You need administrator rights to perform this procedure By default under Windows Server 2008, only the integrated administrator account has these rights Other user accounts do not—even if they belong to the administrator group 1 Open a command prompt window with administrator... containing some welcome text Setting Up PHP After you have successfully installed IIS, you can install PHP and configure it for use with IIS Again, you’ll see how to configure PHP via the IIS Manager application as well as from the command line Only experienced users should use the command-line version; typically you’d use it when there’s no graphic interface (such as under Windows Server 2008 R2 Core edition)... there’s no graphic interface (such as under Windows Server 2008 R2 Core edition) or when you want to automate the installation with a script Installing PHP 1 In Internet Explorer or another browser, open the website http:/ /windows .php. net/ download/ 2 Download the current PHP version 5.3.x (as of this book’s printing, the latest version is 5.3.8) as a zip file Choose the zip file from the VC9 x86... http://go.microsoft.com/FWLink/?Linkid=229620 Follow the instructions to download the PHP_ sample_code.zip file Installing the Code Samples Follow these steps to install the code samples on your computer so that you can use them with the exercises in this book 1 Unzip the PHP_ sample_code.zip file that you downloaded from the book’s website (name a specific directory along with directions to create it, if necessary) 2 If prompted,... manage users in Active Directory with Lightweight Directory Access Protocol (LDAP), or use Windows credentials to provide seamless authentication of your users, PHP is up to the task In addition, Microsoft provides extensive developer documentation on its MSDN developer network and on TechNet, which leaves few common questions unanswered Also, several of Microsoft’s core PHP developers share valuable... conversation going! We’re on Twitter: http://twitter.com/MicrosoftPress Contacting the Author PHP, Windows, and accompanying technologies are constantly being developed and improved If you have ideas or remarks that you would like to share, or have had noteworthy experiences while programming Microsoft technologies with PHP, I would like to hear from you Criticism is welcome, as well You can reach me by email . www.it-ebooks.info www.it-ebooks.info Integrating PHP with Windows ® Arno Hollosi www.it-ebooks.info Published with the authorization of Microsoft Corporation by: O’Reilly. 225 Working with SQL Server 253 PHP and SQL Server . 6 Setting Up PHP 6 Installing PHP