PHP On IIS7 and Server Core
PHP On IIS7 and Server Core
Microsoft
10/26/2013 1
The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. 2007 Microsoft Corporation. All rights reserved. Microsoft, Active Directory, ActiveX, , Visual Basic, Windows, the Windows logo, Windows NT, Windows, Windows Server, and Windows Server System are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are property of their respective owners.
Microsoft
10/26/2013 2
Contents
Contents ................................................................................................................................... 3 Introduction................................................................................................................ 5 Overview of Server Core and IIS 7.0...........................................................................5 Overview of Server Core.......................................................................................... 5 Benefits of a Server Core installation...................................................................6 Overview of IIS 7.0 ................................................................................................. 6 Description and Install Instructions............................................................................8 Server Core Installation........................................................................................... 8 Prerequisites for a Server Core installation..........................................................8 Considerations when deploying a Server Core installation ............................................................................................................................. 8 Steps for manually installing a Server Core installation.......................................9 ................................................................................................................................ 9 Configuring Server Core.......................................................................................... 9 Considerations when configuring a Server Core installation ............................................................................................................................. 9 Steps for configuring a Server Core installation...................................................9 Managing a Server Core installation......................................................................12 Installing IIS 7.0 on Server Core............................................................................ 14 Prerequisites for installing IIS 7.0 on Server Core..............................................14 Considerations when installing IIS 7.0 on Server Core.......................................14 Steps for Installing IIS 7.0 on Server Core..........................................................15 Managing IIS 7.0 on Server Core Installations.......................................................17 Hosting PHP on IIS 7.0 .......................................................................................... 17 Installing Fast-CGI Support................................................................................. 17 Installing PHP on IIS 7.0:..................................................................................... 18 Testing the PHP Configuration ................................................................................ 19 Installing a PHP Application on IIS 7.0................................................................21 Preparation......................................................................................................... 21 Installing Qdig: .................................................................................................. 21 To install QDIG:.................................................................................................. 22
Microsoft
10/26/2013 3
Microsoft
10/26/2013 4
Introduction
This document is to familiarize IT Professionals with the Server Core Installation of Microsoft Windows Server 2008 and Microsoft Internet Information Services 7.0 (IIS 7.0). The advantages of the ease of management provided by IIS 7.0 and the lower infrastructure costs brought by Server Core make it easy to migrate your PHP applications to the IIS 7.0 running on Windows Server Core environment. The goals of this document are to describe and explain how to: Set up the Windows Server 2008 Server Core and IIS 7.0. Install and configure PHP applications on Windows Server 2008 Server Core and IIS 7.0. Set up PHP support and migrate PHP applications on Windows Server 2008 Server Core and IIS 7.0, and how to run PHP on IIS 7.0.
To do this, the Server Core installation option installs only the binary files required by the supported server roles. For example, the Windows Explorer shell is not installed as part of a Server Core installation. Instead, the user interface for a server running a Server Core installation is the command prompt.
Microsoft
10/26/2013 5
Summary The IT administrator can customize the Server Core installation to run only the services required for that particular server. Since Server Core is modular, the specific components are more accessible, leading to a leaner, faster, better experience for the administrator.
2.
are built using a new set of public Web server APIs that all developers can use to extend, replace, or add functionality to the Web server. These APIs are available as native Win32 APIs as well as being available as managed .NET Framework APIs. Developers can also take advantage of the extensibility of event logging, configuration, and administration tool feature-sets available in IIS 7.0, providing a better experience for customers using third-party extensions. 3. Simplified, Distributed XML Configuration model: IIS 7.0 provides developers and administrators with a unified configuration system for storing all IIS and ASP.NET settings in a single XML format, This includes a set of managed code and scripting APIs which access configuration information for the entire Web platform. This new configuration system supports distributed configuration files, which can be stored along with Web site or application content. These improvements have radical implications for how applications are configured and deployed. Now that Web site and application settings are no longer explicitly tied to a centralized configuration store on the local computer, configuration can simply be copied from the developer's workstation to a test server, and then to the production Web server. When a Web site is in production, administrators can share configuration information across multiple front-end Web servers, avoiding replication and manual synchronization issues. Efficient Local and Remote Administration Tools: IIS 7.0 offers a broad set of administration features that simplify the day-to-day tasks of managing Web sites and applications. IIS 7.0 includes: A new graphical user interface (GUI) administration tool IIS Manager, a new command-line utility A new managed API, a command line utility called AppCMD A new WMI provider for automating administration tasks All of these new administration features provide unified support for managing IIS and ASP.NET settings together. The new IIS Manager in IIS 7.0 offers an improved, modular, more efficient tool for managing the Web server. IIS Manager provides support for both IIS and ASP.NET configuration settings, membership users, and role data, as well as runtime diagnostic information. The new UI also enables those who host or administer Web sites to delegate administrative control to developers or content owners, thus reducing cost of ownership and the administrative burden for the IT professional. It supports securely connecting to remote servers over HTTPS (through firewalls) and works in both dedicated and shared hosting environments. 5. Powerful diagnostic capabilities: IIS 7.0 enables developers and IT Professionals to more easily troubleshoot errant Web sites and applications. IIS 7.0 provides runtime diagnostic information to administratorsfor example, what requests are currently executing, how long they have been running, which URLs they are invoking, what client called them, and what Microsoft 10/26/2013 7
4.
their status is. IIS 7.0 makes it possible to troubleshoot failures without having to manually reproduce them. The Failed Request Tracing feature enables server administrators to define error conditions that they wish to monitor. These diagnostic capabilities in IIS 7.0 are extensible as well, so new diagnostic events can be inserted into custom modules. Summary New features in IIS 7.0 provide easy to use, flexible tools for the technical professional. Using IIS 7.0 simplifies Web server management with options that include a flexible extensibility model, powerful diagnostic tools, enhanced security, true XCopy deployment for applications, and improved administration tools. Using the delegated administration features in IIS 7.0, Web hosters can let customers or datacenters manage their own content, which helps reduce the cost of administration. Improved configuration features make it easy to create one configuration file and distribute the configuration changes to multiple servers. The new module features in IIS 7.0 can be independently installed on the server to reduce the attack surface of the server, and reduce administrative overhead where it is not needed. IIS 7.0 is designed to work with existing tools and scripts. The new management and diagnostic features in IIS 7.0 free up IT staff to work on more businesscritical tasks. For more information about IIS 7.0, visit the IIS Web site at: www.iis.net
Microsoft
10/26/2013 8
IIS on Server Core You cannot upgrade from a Server Core installation to a full installation of Windows Server 2008. If you need the Windows user interface or a server role that is not supported in a Server Core installation, you will need to install a full installation of Windows Server 2008.
Microsoft
10/26/2013 9
IIS on Server Core Setting static IP and DNS addresses Activating the server
Notes: A DHCP address is provided by default. You should perform this procedure only if you need to set a static IP address. There is no confirmation after installing components using pkgmgr. You can generate an 'oclist' after the install to ensure that the components are in the 'installed' category. To set the administrative password for the first time: 1. When your computer starts for the first time after the installation completes, press CTRL+ALT+DEL. Type Administrator for the user name and leave the password blank. 2. The system will inform you that the password has expired and will prompt you for a new password. 3. Type your new password. To set a static IP and DNS: 1. At a command prompt, type the following: netsh interface ipv4 show interfaces 2. Make a note of the number shown in the Idx column of the output for your network adapter. If your computer has more than one network adapter, note the number corresponding to the network adapter for which you wish to set a static IP address. 3. At the command prompt, type: netsh interface ipv4 set address name="<ID>" source=static address=<StaticIP> mask=<SubnetMask> gateway=<DefaultGateway> Where: ID is the number from Step 2 above StaticIP is the static IP address that you are setting SubnetMask is the subnet mask for the IP address DefaultGateway is the default gateway 4. At the command prompt, type: netsh interface ipv4 add dnsserver name="<ID>" address=<DNSIP>index=1
Microsoft
10/26/2013 10
Where: ID is the number from Step 2 above DNSIP is the IP address of your DNS server 5. Repeat Step 4 for each DNS server that you want to set, incrementing the index= number each time. Note: If you set the static IP address on the wrong network adapter, you can change back to the DHCP address supplied by using the following command:
netsh interface ipv4 set address name="<ID>" source=dhcp
Where: ID is the number of the network adapter from Step 2 above To change the servers hostname: 1. Determine the current name of the server with the hostname or ipconfig command. 2. At a command prompt, type: netdomrenamecomputer<ComputerName>/NewName:<NewComputerName> 3. Restart the computer. To activate the server
At the command prompt, type: slmgr.vbsato=-
If activation is successful, no message will return in the command prompt. Note: You can also activate by phone, by using a KMS server, or remotely by typing the following command at a command prompt of a computer that is running Windows Vista or Windows Server 2008:
cscript windows\system32\slmgr.vbs<ServerName><UserName><password>:-ato
Summary This new, minimalist version of Windows Server 2008 lets the IT Professional run a more secure, small-footprint server without the overhead, and the exposure, that a GUI imposes. Next well take a look at managing the Server Core installation.
Microsoft
10/26/2013 11
To manage a server running a Server Core installation locally at a command prompt 1. 2. 3. Start a server running a Server Core installation. Log on using an administrator account. At the command prompt, use the applicable command-line tool for the task you want to complete.
To manage a server running a Server Core installation using a terminal server: 1. On the server running a Server Core installation, type the following command at a command prompt: cscript C:\Windows\System32\ Scregedit.wsf /ar 0 This enables the Remote Desktop for Administration mode to accept connections. On another computer, click Start, click Run, type mstsc, and then click OK. In Computer, enter the name of the server running a Server Core installation, and click Connect. Log on using an administrator account. When the command prompt appears, you can manage the computer using the Windows command-line tools. When you have finished remotely managing the computer, type logoff in the command prompt to end your Terminal Server session.
2. 3. 4. 5. 6.
Notes: If you are running the Terminal Services client on a previous version of Windows, you must turn off the higher security level that is set by default in Windows Server 2008. To do this, after step 1, type the following command at the command prompt:
Microsoft
10/26/2013 12
It can be useful to run Cmd.exe in a Command Prompt window on your local computer, rather than in the Terminal Services client. To do this, you need a standard Windows Server 2008 installation and the latest Terminal Services client. To use Terminal Services RemoteApp (TS RemoteApp) to publish cmd.exe to your local computer: 1. 2. Add the Terminal Services role to the standard Windows Server 2008 computer using Server Manager. Start MMC on the standard Windows Server 2008 computer, add the TS RemoteApp snap-in, and then connect the snap-in to a server running a Server Core installation. In the Action pane of the snap-in, click Add Remote Programs, and then navigate to \\<ServerName>\c$\windows\system32\cmd.exe (where ServerName is the name of the server running a Server Core installation). In the Allow list, choose Remote cmd.exe, and then Create RDP package. Connect to the server running a Server Core installation by using the Remote Desktop Protocol package.
3.
4. 5.
To manage a server running a Server Core installation by using the Windows Remote Shell: 1. To enable Windows Remote Shell on a server running a Server Core installation, type the following command at a command prompt: WinRMquickconfig
2.
On another computer, at a command prompt, use WinRS.exe to run commands on a server running a Server Core installation. For example, to perform a directory listing of the Windows folder, type: winrs -r:<ServerName> dir c:\windows Where: ServerName is the name of the server running a Server Core installation. Note: The WinRMquickconfig setting enables a server running a Server Core installation to accept Windows Remote Shell connections. This setting can
Microsoft
10/26/2013 13
IIS on Server Core also be set in an unattended file. For more information about using different security credentials to run commands, see the command-line help for WinRS.exe by typing winrs -?at a command prompt. Summary The Server Core installation provides the following benefits:
Reduced maintenance. Because the Server Core installation installs only what is required for the AD DS, AD LDS, DHCP Server, DNS Server, File Services, Print Services, and Streaming Media Services roles, much less maintenance is required. Reduced attack surface. Because Server Core installations are minimal, fewer applications run on the server, which decreases the attack surface. Reduced management. Because fewer applications and services are installed, there is less to manage. Less disk space required. A Server Core installation requires only about 1 gigabyte (GB) of disk space to install and approximately 2 GB for operations after the installation.
Microsoft
10/26/2013 14
installations. Because there is no support for managed code, the following IIS features are not available in Server Core installations: IIS-ASPNET IIS-NetFxExtensibility IIS-ManagementConsole IIS-ManagementService IIS-LegacySnapIn IIS-FTPManagement WAS-NetFxEnvironment WAS-ConfigurationAPI
Notes: To uninstall the Web Server (IIS) role, use the following command: start /w pkgmgr /uu:IIS-WebServerRole;WASWindowsActivationService;WAS-ProcessModel This is the basic IIS 7.0 Server installation. Administrators can optimize their IIS 7.0 installation by adding additional IIS 7.0 Modules and features as needed. For detailed IIS 7.0 module installation instructions and reference information, go to: http://www.iis.net/articles/view.aspx/IIS7/Managing-IIS7/Configuring-the-IIS7Runtime/Configuring-Modules/IIS7-Modules-Overview?Page=4 Summary Featuring modular structure and flexible installation, advanced CGI controls and config file automation, IIS 7.0 is a powerful, adaptable Web server. IIS 7.0 functionality will be enhanced as Microsoft works with Zend to improve PHP support on Windows.
Microsoft
10/26/2013 15
Microsoft
10/26/2013 16
Windows PowerShell Overview/Info/download http://www.microsoft.com/windowsserver2003/technologies/management/power shell/default.mspx Windows Powershell Scripts Samples: http://www.microsoft.com/technet/scriptcenter/scripts/msh/default.mspx? mfr=true
Create the PHP/FastCGI handler mapping from the command line by typing the following two AppCmd.exe commands: Notes: 1. AppCmd.exe is a new command-line tool included with IIS 7.0. AppCmd.exe can be found at %WinDir%\System32\InetSrv directory. 2. Depending on the PHP installation location, paths to executables on the hard disk may require updates. All AppCmd example commands above assume that PHP installation is in D:\PHP folder.
>AppCmd set config /section:system.webServer/fastCGI /+ [fullPath='d:\php\php-cgi.exe'] >AppCmd set config /section:system.webServer/handlers /+ [name='PHPFastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProc essor='d:\php\php-cgi.exe',resourceType='Either']
5. Copy the entire contents of the PHP archive you uncompressed previously into %SystemDrive%\PHP
Microsoft
10/26/2013 18
IIS on Server Core 6. Execute the following command: rename %SystemDrive%\PHP\PHP.INI-Recommended %SystemDrive %\PHP\PHP.INI
1.
From the command line, launch notepad.exe. In the empty file, type or paste the following text: <? phpinfo(); ?>
2.
3.
From a connected computer, open a browser window, and point it to: http://%systemhost%/phpinfo.php.
4.
Microsoft
10/26/2013 19
Summary IIS 7.0s advanced standards support, support for FastCGI and command line interface provide the administrator with the best toolset available for running PHP.
Microsoft
10/26/2013 20
Preparation
Open PHP.ini in notepad.exe and make the following changes: Change The line: extension_dir = "./" To the following: extension_dir = "C:\PHP\ Change The line: register_long_arrays = on To the following: register_long_arrays = off Add the following line to PHP.ini in the "Extensions" section: extension=php_gd.dll Save the PHP.INI file and close Windows Notepad.
Installing Qdig:
Qdig is an easy-to-use PHP script that dynamically presents digital image files as an online gallery or set of galleries. Qdig supports image captions and display of EXIF image metadata. The script can generate thumbnails and smaller versions of large images such as digital camera photos. To download and install the QDIG application, visit: http://qdig.sourceforge.net/
Microsoft
10/26/2013 21
To install QDIG:
1. Unzip the contents of the QDIG application into a folder on your computer. 2. Create a directory on the Web server for the application example: C:\inetpub\wwwroot\qdig 3. Use XCopy to copy the contents of the Qdig application archive to this directory 4. Copy several jpeg image files into the directory. 5. From a connected computer, open a browser window, and point it to: http://%systemhost%/qdig/index.php. You should now see the QDIG gallery and images, as below:
Figure 2
Microsoft
10/26/2013 22
Conclusion
The combination of IIS 7.0 on Server Core provides IT Professionals with a lean, fast, capable command-line based Web server system that supports PHP applications and provides modern management within an enterprise-level server system. Server Cores simplicity, small footprint, and focused capabilities make an ideal foundation for the IIS 7.0 Web server. IIS 7.0 makes Web sites and applications more secure by automatically isolating them, providing sandboxed configurations and unique process identity. IIS 7.0 also lowers costs by providing a scalable shared hosting architecture capable of hosting thousands of Web sites on a single server without sacrificing isolation or reliability. These features provide the IT community with a secure, reliable Web server toolset that integrates into the corporate enterprise environment.
Microsoft
10/26/2013 23