Вы находитесь на странице: 1из 14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Install and Configure PHP


ByTali SmithNovember 15, 2009

Introduction
The fastest and easiest way to install PHP on Internet Information Services IIS is by using the
MicrosoftWeb Platform Installer Web PI. Web PI completely automates setting up IIS, FastCGI, and the
latest version of PHP from the php.net Web site. With Web PI, you can navigate to the Web Platform tab
and select PHP under Framework and Runtimes customize link. Alternately, use the instructions that follow
as guidance for installing PHP with WindowsInstaller or using a compressed Zip file installation.
There are two builds for each PHP version: one is threadsafe, and one is not referred to as the nonthread
safe [NTS] version. The threadsafe version is designed for environments where the Web server core can
keep the PHP engine in memory, running multiple treads of execution for different Web requests
simultaneously. The architecture of IIS and the FastCGI extension provide an isolation model that keeps
requests separate, removing the need for a threadsafe version. The NTS version does not have any of the
code that allows PHP to manage multiple threads. As a result, there is a performance improvement on IIS
when using the NTS version when compared to the treadsafe version because the NTS version avoids
unnecessary threadsafety checks FastCGI ensures a singlethreaded execution environment.

Install PHP
There are two main ways to install PHP on a Windowsbased computer: download the Windows Installer or
use the Windows Zip file from thePHP Web site. Either method will get PHP working, but both have some
extra steps that are needed to make PHP work well.
Windows Installer
The Windows Installer version can get a complete PHP environment up and running, but the installation of
extensions can be confusing. By default, no extensions are installed, and this can adversely affect the
usefulness of the PHP installation. Alternately, all of the extensions can be installed; this results in an unstable
system because some of the extensions can conflict with others. It is generally easier to use the Zip file
installation.
Zip File Installation
To use the Zip file installation, follow the instructions inUsing FastCGI to Host PHP Applications on IIS 7.0 and
http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

1/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Above. The Zip file installation installs many of the extensions that are available for the Windows Installer
version; however, none of the extensions are enabled until their entries in the Php.ini file are set up.
1. Download thelatest nonthreadsafe Zip file packagewith binaries of PHP. UnderWindows Binaries, click
on the most current PHP nonthreadsafe Zip package to download the PHP files.
2. Unpack the files to a directory of your choice for example, C:\PHP on your IIS server.
3. Rename thePhp.inirecommendedtophp.ini.
4. Open thePhp.inifile in a text editor, then uncomment and modify settings as follows:
a. Setfastcgi.impersonate = 1.
FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to
define the security context that the request runs under.
b. Setcgi.fix_pathinfo=0
Thecgi.fix_pathinfoprovidesPATH_INFO/PATH_TRANSLATEDsupport for Common Gateway Interface CGI.
Setting this to 1 will cause PHP CGI to fix its paths to conform to the specification.
c. Setcgi.force_redirect = 0.
d. Setopen_basedirto point to a folder or network path where the content of the Web sites is located.
e. Setextension_dirto point to a location where PHP extensions reside. For PHP 5.2.X, this is
typicallyextension_dir = "./ext".
f. Seterror_log=C:php_errors.log
This can help with troubleshooting.
g. Enable the required PHP extension by uncommenting corresponding lines. More information follows in
the section,Extensions.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

2/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Figure 1 Windows extensions


5. Click onStart,Settings,Control Panel, and then doubleclick on theSystemicon using the class view.
6. Click on theAdvanced systemsettingslink in the left column.
7. From theSystem Propertieswindow, click on theAdvancedtab, and then click on theEnvironment
Variablesbutton at the bottom.
8. Select thePathvariable from theSystem Variablessection, and then click onEdit. Add:c:\phpto your
system path.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

3/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Figure 2: Edit System Variable


9. ClickOKuntil you have exited the System Properties window.
10. Start IIS Manager by clicking onStart,Programs,Administrative Tools, and thenInternet Information
Services IIS Manager.
11. From theIIS Manager, click on thehostnameof your server in theConnectionspanel on the left.
12. Doubleclick on theHandler Mappingsicon.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

4/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Figure 3: Internet Information Services (IIS) Manager


13. From theHandler MappingsActionspanel, click onAdd Module Mapping.

Figure 4: Handler Mappings


14. Type the following information into the appropriate text boxes, and then clickOK.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

5/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Request path:*.php
Module: FastCGImodule
Executable:C:\php\phpcgi.exe
Name:FastCGI

Figure 5: Add Script Map


15. ClickOK, and thenclickYes.
16. In the left panel, click on your servershostname, and then doubleclick on theDefault Documenticon.
17. From theActionspanel on the right, clickAdd.
18. Enterindex.phpas the new default document name, and then clickOK.
19. Enterdefault.phpas the new default document name, and then clickOK.
20. In the left panel, click on your servershostname.
21. In theActionspanel on the right, clickRestart.
http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

6/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

22. Create a new text document, and save it asc:\inetpub\wwwroot\phpinfo.phpwith the following content:
<?phpphpinfo();?>

23. You should now see the PHP information page at http://localhost/phpinfo.php.

Figure 6: PHP information page

Extensions
It is important to determine which extensions are needed by the applications that will be running and then to
limit the installed extensions to only those. For a typical opensource application installation, for example, the
following extensions are installed:
Database ExtensionsMost opensource applications that use MySQL for a database engine use either
thephp_mysqlor thephp_mysqliextensions. For new development work, either of these extensions
work well, or consider using the PDO versions of the MySQL driver PDO is a PHP extension providing a
http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

7/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

dataaccess abstraction layer that can be used with a variety of databases; this extra layer of
abstraction provides a richer set of object database functionality and controls. If MicrosoftSQL
Serveror an express version, such as MicrosoftSQL Server2008 Express or MicrosoftSQL
Server2005 Express Edition is the database engine, use thephp_mssqlextension for opensource
applications. For new development work, use the PDO version of the SQL driver.
Image Handling ExtensionsMany of the opensource applications that enable work with images
make use of the GD2 extension php_gd2, which has a number of good basic image manipulation
application programming interfaces APIs. Some applications use theImageMagick application and
libraries. There is also aphp_exiflibrary for working with the extended information that modern digital
cameras store within the images.
Internationalization and Localization ExtensionsThe two most commonly used extensions for i18n
and l10n arephp_mbstringMultiByte String andphp_gettextNative Language Support. Many of
the opensource applications use one or both of these.
Web Services ExtensionsChoose the Web services extensions based on the services desired. For PHP,
the SOAP extension is widely used. The XMLRPC extension is often used in conjunction with SOAP and
other services.

PHP.INI File Settings


The Php.ini file provides PHP with configuration and environmental information. Below are a number of
settings for the Php.ini file that help PHP work better with Windows.

REQUIRED SETTINGS:
extension_dir = <PATH TO EXTENSIONS>
The extension_dir needs to point to the directory where the PHP extensions are stored. The path can be
fully qualified for example, C:\PHP\ext or relative for example, .\ext. Extensions that are specified
lower in the Php.ini file need to be located in the extension_dir. If the extensions specified are not in
the extension_dir, then PHP will give a warning message at the start of script execution, and the
application may show errors because of the missing functionality.
extension = xxxxxx.dll
For each extension enabled, a corresponding extension= directive that tells PHP which extensions in
the extension_dir to load at startup time is necessary.
http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

8/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

log_errors=On
PHP errors can also go through the PHP error logging facility. This can be used to send errors to a file
or to a service for example, syslog and works with the error_logdirective described below. When
running under IIS, log_errors must be enabled with a valid error_log. Otherwise, FastCGI considers any
startup messages which may be benign as an error condition, which generates an HTTP 500 return
error code to the browser.
error_log=<path_to_error_log_file
The error_log needs to specify the fully qualified, or relative, path to the file where the PHP error log is
stored. This file needs to be writable for the IIS service. The most common places for this file are in
various temporary directories for example, C:\inetpub\temp\phperrors.log. That puts the log in a
place that IIS can use, and also keeps the log close to where PHP applications are running.
cgi.force_redirect = 0
This directive is required for running under IIS. It is a directory security facility required by many other
Web servers; however, enabling it under IIS will cause the PHP engine to fail on Windows.
cgi.fix_pathinfo = 1
This lets PHP access real path info following the CGI specification. The IIS FastCGI implementation
needs this extension set.
fastcgi.impersonate = 1
FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS
to define the security context that the request runs under.
fastcgi.logging = 0
FastCGI logging should be disabled on IIS. If it is left enabled, then any messages of any class are
treated by FastCGI as error conditions, which will cause IIS to generate an HTTP 500 exception.

OPTIONAL SETTINGS:
max_execution_time=##
This directive sets the maximum amount of time that can be taken executing any given script. The
default is 30 seconds. Some applications need more time to process batch operations for example,
Gallery2 loading multiple images from a remote location. However, setting the execution time higher
than 300 seconds is not advised because there are often other parts of the connection that cannot
support such a long execution time.
memory_limit=###M
The amount of memory available for the PHP process in MB. The default is 128 MB, which is
http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

9/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

appropriate for most PHP applications.


display_errors=Off
This directive determines whether to include any error messages in the stream that it returns to the
Web server. If turned on, PHP will send the classes of errors that are defined with
theerror_reportingdirective back to IIS as part of the error stream. Many of the opensource
applications bypass error reporting by executing commands prefaced with @. This allows the
applications to control error handling.
Mail functions
PHP is configured by default to send outbound mail through an SMTP server located on the same
system as the Web server. Note that most Windows installations usually have the Web and mail servers
on separate systems.

Enable PHP Session State


1. InWindowsExplorer, create thesessionsubdirectory in the PHP installation directory.
2. Rightclick thesessiondirectory, and selectProperties.
3. In theSecuritytab, clickEdit.
4. ClickAdd, and enterIIS_IUSRSforEnter the object names to select.
5. ClickOK.
6. Select theModifypermission check box, and clickOK.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

10/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Figure 7: Permissions for session folder


7. ClickOKin theSession Propertieswindow.
8. Openphp.iniin the PHP installation directory, and set thesession.save_pathsetting to
thesessionsubdirectory:
session.save_path="C:\php\session"

9. Save and close the file.


10. ClickStart, and then selectCommand Prompt.
11. Typerunas /user:administrator cmd.exeto enable elevated permissions.
12. Typeiisresetat the command prompt, and then press the ENTER key.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

11/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Figure 8: IISRESET command


Note that PHP uses filebased session state by default. You can modify a number of additional session
settings, including whether cookie or URL sessions should be used, and whether sessions are created on the
first request or need to be explicitly created.
13. Test the session state by using Windows Explorer, navigate toC:\inetpub\wwwroot.
14. Create a folder and rename itphpapp.
15. Createsession.phpin thephpappdirectory.
16. Paste the following into it:
<?php
session_start();
$counter=isset($_SESSION['counter'])?$_SESSION['counter']:0;
$counter++;
print"Youhavevisitedthispage$countertimesduringthissession";
$_SESSION['counter']=$counter;
?>

17. Save and close the file.


18. StartInternet Explorer, and navigate tohttp://localhost/session.php.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

12/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

Figure 9: Using session state


19. Observe that the counter is 1.
20. Requesthttp://localhost/session.phpagain, or pressF5.

Figure 10: Using session state


21. Observe that the counter is 2.
Note:This article uses information from Using FastCGI to Host PHP Applications on IIS 7.0 and Above by
Ruslan Yakushev, published on December 5, 2007.

Links for Further Information


http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

13/14

4/4/2016

Install and Configure PHP : The Official Microsoft IIS Site

PHP on Windows Training Kit.


Installing PHP on Windows Server 2008.
PHP on IIS7.
Deploying IIS 7.5 + FASTCGI + PHP on Server Core.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

14/14

Вам также может понравиться