Installation on old Windows systemsThis section applies to Windows 98/Me and Windows NT/2000/XP/2003. PHP will not work on 16 bit platforms such as Windows 3.1 and sometimes we refer to the supported Windows platforms as Win32.
If you have a development environment such as Microsoft Visual Studio, you can also PHP from the original source code. Once you have PHP installed on your Windows system, you may also want to load various extensions for added functionality. Manual Installation StepsThis section contains instructions for manually installing and configuring PHP on Microsoft Windows. Selecting and downloading the PHP distribution packageDownload the PHP zip binary distribution from » PHP for Windows: Binaries and Sources. There are several different versions of the zip package - to choose the right version for you, follow the detailed guide on the » download page. The PHP package structure and contentUnpack the content of the zip archive into a directory of your choice, for example C:\PHP\. The directory and file structure extracted from the zip will look as below: Example #1 PHP 5 package structure c:\php | +--dev | | | |-php5ts.lib -- php5.lib in non thread safe version | +--ext -- extension DLLs for PHP | | | |-php_bz2.dll | | | |-php_cpdf.dll | | | |-... | +--extras -- empty | +--pear -- initial copy of PEAR | | |-go-pear.bat -- PEAR setup script | |-... | |-php-cgi.exe -- CGI executable | |-php-win.exe -- executes scripts without an opened command prompt | |-php.exe -- Command line PHP executable (CLI) | |-... | |-php.ini-development -- default php.ini settings | |-php.ini-production -- recommended php.ini settings | |-php5apache2_2.dll -- does not exist in non thread safe version | |-php5apache2_2_filter.dll -- does not exist in non thread safe version | |-... | |-php5ts.dll -- core PHP DLL ( php5.dll in non thread safe version) | |-... Below is the list of the modules and executables included in the PHP zip distribution:
Changing the php.ini fileAfter the php package content has been extracted, copy the php.ini-production into php.ini in the same folder. If necessary, it is also possible to place the php.ini into any other location of your choice but that will require additional configuration steps as described in PHP Configuration. The php.ini file tells PHP how to configure itself, and how to work with the environment that it runs in. Here are a number of settings for the php.ini file that help PHP work better with Windows. Some of these are optional. There are many other directives that may be relevant to your environment - refer to the list of php.ini directives for more information. Required directives:
Optional directives
PHP is now setup on your system. The next step is to choose a web server, and enable it to run PHP. Choose a web server from the table of contents. In addition to running PHP via a web server, PHP can run from the command line just like a .BAT script. See Microsoft IISThis section contains PHP installation instructions specific to Microsoft Internet Information Services (IIS). Microsoft IIS 5.1 and IIS 6.0This section contains instructions for manually setting up Internet Information Services (IIS) 5.1 and IIS 6.0 to work with PHP on Microsoft Windows XP and Windows Server 2003. For instructions on setting up IIS 7.0 and later versions on Windows Vista, Windows Server 2008, Windows 7 and Windows Server 2008 R2 refer to Microsoft IIS 7.0 and later. Configuring IIS to process PHP requestsDownload and install PHP in accordance to the instructions described in manual installation steps
Configure the CGI- and FastCGI-specific settings in php.ini file as shown below: Example #2 CGI and FastCGI settings in php.ini fastcgi.impersonate = 1 fastcgi.logging = 0 cgi.fix_pathinfo=1 cgi.force_redirect = 0 Download and install the » Microsoft FastCGI Extension for IIS 5.1 and 6.0. The extension is available for 32-bit and 64-bit platforms - select the right download package for your platform. Configure the FastCGI extension to handle PHP-specific requests by running the command shown below. Replace the value of the "-path" parameter with the absolute file path to the php-cgi.exe file. Example #3 Configuring FastCGI extension to handle PHP requests cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" ^ -extension:php -path:"C:\PHP\php-cgi.exe" This command will create an IIS script mapping for *.php file extension, which will result in all URLs that end with .php being handled by FastCGI extension. Also, it will configure FastCGI extension to use the executable php-cgi.exe to process the PHP requests.
Impersonation and file system accessIt is recommended to enable FastCGI impersonation in PHP when using IIS. This is controlled by the fastcgi.impersonate directive in php.ini file. When impersonation is enabled, PHP will perform all the file system operations on behalf of the user account that has been determined by IIS authentication. This ensures that even if the same PHP process is shared across different IIS web sites, the PHP scripts in those web sites will not be able to access each others' files as long as different user accounts are used for IIS authentication on each web site. For example IIS 5.1 and IIS 6.0, in its default configuration, has anonymous authentication enabled with built-in user account IUSR_<MACHINE_NAME> used as a default identity. This means that in order for IIS to execute PHP scripts, it is necessary to grant IUSR_<MACHINE_NAME> account read permission on those scripts. If PHP applications need to perform write operations on certain files or write files into some folders then IUSR_<MACHINE_NAME> account should have write permission to those. To determine which user account is used by IIS anonymous authentication, follow these steps:
To modify the permissions settings on files and folders, use the Windows Explorer user interface or icacls command. Example #4 Configuring file access permissions icacls C:\inetpub\wwwroot\upload /grant IUSR:(OI)(CI)(M) Set index.php as a default document in IISThe IIS default documents are used for HTTP requests that do not specify a document name. With PHP applications, index.php usually acts as a default document. To add index.php to the list of IIS default documents, follow these steps:
FastCGI and PHP Recycling configurationConfigure IIS FastCGI extension settings for recycling of PHP processes by using the commands shown below. The FastCGI setting instanceMaxRequests controls how many requests will be processed by a single php-cgi.exe process before FastCGI extension shuts it down. The PHP environment variable PHP_FCGI_MAX_REQUESTS controls how many requests a single php-cgi.exe process will handle before it recycles itself. Make sure that the value specified for FastCGI InstanceMaxRequests setting is less than or equal to the value specified for PHP_FCGI_MAX_REQUESTS. Example #5 Configuring FastCGI and PHP recycling cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -InstanceMaxRequests:10000 cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000 Configuring FastCGI timeout settingsIncrease the timeout settings for FastCGI extension if there are applications that have long running PHP scripts. The two settings that control timeouts are ActivityTimeout and RequestTimeout. Refer to » Configuring FastCGI Extension for IIS 6.0 for more information about those settings. Example #6 Configuring FastCGI timeout settings cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -ActivityTimeout:90 cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -RequestTimeout:90 Changing the Location of php.ini filePHP searches for php.ini file in several locations and it is possible to change the default locations of php.ini file by using PHPRC environment variable. To instruct PHP to load the configuration file from a custom location run the command shown below. The absolute path to the directory with php.ini file should be specified as a value of PHPRC environment variable. Example #7 Changing the location of php.ini file cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -EnvironmentVars:PHPRC:"C:\Some\Directory\" Microsoft IIS 7.0 and laterThis section contains instructions for manually setting up Internet Information Services (IIS) 7.0 and later to work with PHP on Microsoft Windows Vista SP1, Windows 7, Windows Server 2008 and Windows Server 2008 R2. For instructions on setting up IIS 5.1 and IIS 6.0 on Windows XP and Windows Server 2003 refer to Microsoft IIS 5.1 and IIS 6.0. Enabling FastCGI support in IISFastCGI module is disabled in default installation of IIS. The steps to enable it differ based on the version of Windows being used. To enable FastCGI support on Windows Vista SP1 and Windows 7:
To enable FastCGI support on Windows Server 2008 and Windows Server 2008 R2:
Configuring IIS to process PHP requestsDownload and install PHP in accordance to the instructions described in manual installation steps
Configure the CGI- and FastCGI-specific settings in php.ini file as shown below: Example #8 CGI and FastCGI settings in php.ini fastcgi.impersonate = 1 fastcgi.logging = 0 cgi.fix_pathinfo=1 cgi.force_redirect = 0 Configure IIS handler mapping for PHP by using either IIS Manager user interface or a command line tool. Using IIS Manager user interface to create a handler mapping for PHPFollow these steps to create an IIS handler mapping for PHP in IIS Manager user interface:
Using command line tool to create a handler mapping for PHPUse the command shown below to create an IIS FastCGI process pool which will use php-cgi.exe executable for processing PHP requests. Replace the value of the fullPath parameter with the absolute file path to the php-cgi.exe file. Example #9 Creating IIS FastCGI process pool %windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI ^ /+[fullPath='c:\PHP\php-cgi.exe'] Configure IIS to handle PHP specific requests by running the command shown below. Replace the value of the scriptProcessor parameter with the absolute file path to the php-cgi.exe file. Example #10 Creating handler mapping for PHP requests %windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers ^ /+[name='PHP_via_FastCGI', path='*.php',verb='*',modules='FastCgiModule',^ scriptProcessor='c:\PHP\php-cgi.exe',resourceType='Either'] This command creates an IIS handler mapping for *.php file extension, which will result in all URLs that end with .php being handled by FastCGI module.
Impersonation and file system accessIt is recommended to enable FastCGI impersonation in PHP when using IIS. This is controlled by the fastcgi.impersonate directive in php.ini file. When impersonation is enabled, PHP will perform all the file system operations on behalf of the user account that has been determined by IIS authentication. This ensures that even if the same PHP process is shared across different IIS web sites, the PHP scripts in those web sites will not be able to access each other's files as long as different user accounts are used for IIS authentication on each web site. For example IIS 7, in its default configuration, has anonymous authentication enabled with built-in user account IUSR used as a default identity. This means that in order for IIS to execute PHP scripts, it is necessary to grant IUSR account read permission on those scripts. If PHP applications need to perform write operations on certain files or write files into some folders then IUSR account should have write permission to those. To determine what user account is used as an anonymous identity in IIS 7 use the following command. Replace the "Default Web Site" with the name of IIS web site that you use. In the output XML configuration element look for the userName attribute. Example #11 Determining the account used as IIS anonymous identity %windir%\system32\inetsrv\appcmd.exe list config "Default Web Site" ^ /section:anonymousAuthentication <system.webServer> <security> <authentication> <anonymousAuthentication enabled="true" userName="IUSR" /> </authentication> </security> </system.webServer>
To modify the permissions settings on files and folders, use the Windows Explorer user interface or icacls command. Example #12 Configuring file access permissions icacls C:\inetpub\wwwroot\upload /grant IUSR:(OI)(CI)(M) Set index.php as a default document in IISThe IIS default documents are used for HTTP requests that do not specify a document name. With PHP applications, index.php usually acts as a default document. To add index.php to the list of IIS default documents, use this command: Example #13 Set index.php as a default document in IIS %windir%\system32\inetsrv\appcmd.exe set config ^ -section:system.webServer/defaultDocument /+"files.[value='index.php']" ^ /commit:apphost FastCGI and PHP Recycling configurationConfigure IIS FastCGI settings for recycling of PHP processes by using the commands shown below. The FastCGI setting instanceMaxRequests controls how many requests will be processed by a single php-cgi.exe process before IIS shuts it down. The PHP environment variable PHP_FCGI_MAX_REQUESTS controls how many requests a single php-cgi.exe process will handle before it recycles itself. Make sure that the value specified for FastCGI InstanceMaxRequests setting is less than or equal to the value specified for PHP_FCGI_MAX_REQUESTS. Example #14 Configuring FastCGI and PHP recycling %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^ /[fullPath='c:\php\php-cgi.exe'].instanceMaxRequests:10000 %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^ /+"[fullPath='C:\{php_folder}\php-cgi.exe'].environmentVariables.^ [name='PHP_FCGI_MAX_REQUESTS',value='10000']" FastCGI timeout settingsIncrease the timeout settings for FastCGI if it is expected to have long running PHP scripts. The two settings that control timeouts are activityTimeout and requestTimeout. Use the commands below to change the timeout settings. Make sure to replace the value in the fullPath parameter to contain the absolute path to the php-cgi.exe file. Example #15 Configuring FastCGI timeout settings %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^ /[fullPath='C:\php\php-cgi.exe',arguments=''].activityTimeout:"90" /commit:apphost %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi ^ /[fullPath='C:\php\php-cgi.exe',arguments=''].requestTimeout:"90" /commit:apphost Changing the Location of php.ini filePHP searches for php.ini file in several locations and it is possible to change the default locations of php.ini file by using PHPRC environment variable. To instruct PHP to load the configuration file from a custom location run the command shown below. The absolute path to the directory with php.ini file should be specified as a value of PHPRC environment variable. Example #16 Changing the location of php.ini file appcmd.exe set config -section:system.webServer/fastCgi ^ /+"[fullPath='C:\php\php.exe',arguments=''].environmentVariables.^ [name='PHPRC',value='C:\Some\Directory\']" /commit:apphost Apache 1.3.x on Microsoft WindowsThis section contains notes and hints specific to Apache 1.3.x installs of PHP on Microsoft Windows systems. There are also
There are two ways to set up PHP to work with Apache 1.3.x on Windows. One is to use the CGI binary (php.exe for PHP 4 and php-cgi.exe for PHP 5), the other is to use the Apache Module DLL. In either case you need to edit your httpd.conf to configure Apache to work with PHP, and then restart the server. It is worth noting here that now the SAPI module has been made more stable under Windows, we recommend it's use above the CGI binary, since it is more transparent and secure. Although there can be a few variations of configuring PHP under Apache, these are simple enough to be used by the newcomer. Please consult the Apache Documentation for further configuration directives. After changing the configuration file, remember to restart the server, for example, NET STOP APACHE followed by NET START APACHE, if you run Apache as a Windows Service, or use your regular shortcuts.
Installing as an Apache moduleYou should add the following lines to your Apache httpd.conf file:
Example #17 PHP as an Apache 1.3.x module This assumes PHP is installed to c:\php. Adjust the path if this is not the case. For PHP 4: # Add to the end of the LoadModule section # Don't forget to copy this file from the sapi directory! LoadModule php4_module "C:/php/php4apache.dll" # Add to the end of the AddModule section AddModule mod_php4.c For PHP 5: # Add to the end of the LoadModule section LoadModule php5_module "C:/php/php5apache.dll" # Add to the end of the AddModule section AddModule mod_php5.c For both: # Add this line inside the <IfModule mod_mime.c> conditional brace AddType application/x-httpd-php .php # For syntax highlighted .phps files, also add AddType application/x-httpd-php-source .phps Installing as a CGI binaryIf you unzipped the PHP package to C:\php\ as described in the Manual Installation Steps section, you need to insert these lines to your Apache configuration file to set up the CGI binary: Example #18 PHP and Apache 1.3.x as CGI ScriptAlias /php/ "c:/php/" AddType application/x-httpd-php .php # For PHP 4 Action application/x-httpd-php "/php/php.exe" # For PHP 5 Action application/x-httpd-php "/php/php-cgi.exe" # specify the directory where php.ini is SetEnv PHPRC C:/php Warning
A server deployed in CGI mode is open to several possible vulnerabilities. Please read our CGI security section to learn how to defend yourself from such attacks. If you would like to present PHP source files syntax highlighted, there is no such convenient option as with the module version of PHP. If you chose to configure Apache to use PHP as a CGI binary, you will need to use the highlight_file function. To do this simply create a PHP script file and add this code: <?php highlight_file('some_php_script.php'); ?>. Apache 2.x on Microsoft WindowsThis section contains notes and hints specific to Apache 2.x installs of PHP on Microsoft Windows systems. We also
You are strongly encouraged to consult the » Apache Documentation to get a basic understanding of the Apache 2.x Server. Also consider reading the » Windows specific notes for Apache 2.x before reading on here. Apache 2.x is designed to run on the Windows version designated as server platforms, such as Windows NT 4.0, Windows 2000, Windows XP, or Windows 7. While Apache 2.x works tolerably well on Windows 9x, support on these platforms is incomplete, and some things will not work correctly. There is no plan to remedy this situation. Download the most recent version of » Apache 2.x and a fitting PHP version. Follow the Manual Installation Steps and come back to go on with the integration of PHP and Apache. There are three ways to set up PHP to work with Apache 2.x on Windows. You can run PHP as a handler, as a CGI, or under FastCGI.
Installing as an Apache handlerYou need to insert the following lines into your Apache httpd.conf configuration file to load the PHP module for Apache 2.x: Example #19 PHP and Apache 2.x as handler # LoadModule php5_module "c:/php/php5apache2.dll" AddHandler application/x-httpd-php .php # configure the path to php.ini PHPIniDir "C:/php"
The above configuration will enable PHP handling of any file that has a .php extension, even if there are other file extensions. For example, a file named example.php.txt will be executed by the PHP handler. To ensure that only files that end in .php are executed, use the following configuration instead: <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Running PHP as CGIYou should consult the » Apache CGI documentation for a more complete understanding of running CGI on Apache. To run PHP as CGI, you'll need to place your php-cgi files in a directory designated as a CGI directory using the ScriptAlias directive. You will then need to insert a #! line in the PHP files, pointing to the location of your PHP binary: Example #20 PHP and Apache 2.x as CGI #!C:/php/php.exe <?php phpinfo(); ?> Warning
A server deployed in CGI mode is open to several possible vulnerabilities. Please read our CGI security section to learn how to defend yourself from such attacks. Running PHP under FastCGIRunning PHP under FastCGI has a number of advantages over running it as a CGI. Setting it up this way is fairly straightforward: Obtain mod_fcgid from » http://httpd.apache.org/mod_fcgid/. Win32 binaries are available for download from that site. Install the module according to the instructions that will come with it. Configure your web server as shown below, taking care to adjust any paths to reflect your how you have installed things on your particular system: Example #21 Configure Apache to run PHP as FastCGI LoadModule fcgid_module modules/mod_fcgid.so # Where is your php.ini file? FcgidInitialEnv PHPRC "c:/php" AddHandler fcgid-script .php FcgidWrapper "c:/php/php-cgi.exe" .php Sun, iPlanet and Netscape servers on Microsoft WindowsThis section contains notes and hints specific to Sun Java System Web Server, Sun ONE Web Server, iPlanet and Netscape server installs of PHP on Windows. From PHP 4.3.3 on you can use PHP scripts with the NSAPI module to Apache compatibility are also available. For support in current web servers CGI setup on Sun, iPlanet and Netscape serversTo install PHP as a CGI handler, do the following:
More details about setting up PHP as a CGI executable can be found here: » http://benoit.noss.free.fr/php/install-php.html NSAPI setup on Sun, iPlanet and Netscape serversTo install PHP with NSAPI, do the following:
CGI environment and recommended modifications in php.iniImportant when writing PHP scripts is the fact that Sun JSWS/Sun ONE WS/iPlanet/Netscape is a multithreaded web server. Because of that all requests are running in the same process space (the space of the web server itself) and this space has only one environment. If you want to get CGI variables like PATH_INFO, HTTP_HOST etc. it is not the correct way to try this in the old PHP way with getenv or a similar way (register globals to environment, $_ENV). You would only get the environment of the running web server without any valid CGI variables!
Simply change your scripts to get CGI variables in the correct way for PHP 4.x by using the superglobal $_SERVER. If you have older scripts which use $HTTP_HOST, etc., you should turn on register_globals in php.ini and change the variable order too (important: remove "E" from it, because you do not need the environment here): variables_order = "GPCS" register_globals = On Special use for error pages or self-made directory listings (PHP >= 4.3.3)You can use PHP to generate the error pages for "404 Not Found" or similar. Add the following line to the object in obj.conf for every error page you want to overwrite: Error fn="php4_execute" code=XXX script="/path/to/script.php" [inikey=value inikey=value...] Another possibility is to generate self-made directory listings. Just create a PHP script which displays a directory listing and replace the corresponding default Service line for type="magnus-internal/directory" in obj.conf with the following: Service fn="php4_execute" type="magnus-internal/directory" script="/path/to/script.php" [inikey=value inikey=value...] Note about nsapi_virtual and subrequests (PHP >= 4.3.3)The NSAPI module now supports the nsapi_virtual function (alias: virtual) to make subrequests on the web server and insert the result in the web page. The problem is, that this function uses some undocumented features from the NSAPI library. Under Unix this is not a problem, because the module automatically looks for the needed functions and uses them if available. If not, nsapi_virtual is disabled. Under Windows limitations in the DLL handling need the use of a automatic detection of the most recent ns-httpdXX.dll file. This is tested for servers till version 6.1. If a newer version of the Sun server is used, the detection fails and nsapi_virtual is disabled. If this is the case, try the following: Add the following parameter to php4_init in magnus.conf/obj.conf: Init fn=php4_init ... server_lib="ns-httpdXX.dll" You can check the status by using the phpinfo function.
Sambar Server on Microsoft WindowsThis section contains notes and hints specific to the » Sambar Server for Windows.
This list describes how to set up the ISAPI module to work with the Sambar server on Windows.
Xitami on Microsoft WindowsThis section contains notes and hints specific to » Xitami on Windows.
This list describes how to set up the PHP CGI binary to work with Xitami on Windows.
Warning
A server deployed in CGI mode is open to several possible vulnerabilities. Please read our CGI security section to learn how to defend yourself from such attacks.
Building from sourceThis chapter teaches how to compile PHP from sources on windows, using Microsoft's tools. To compile PHP with cygwin, please refer to Installation on Unix systems. See the Wiki documentation at: » http://wiki.php.net/internals/windows/stepbystepbuild Installation of extensions on WindowsAfter installing PHP and a web server on Windows, you will probably want to install some extensions for added functionality. You can choose which extensions you would like to load when PHP starts by modifying your php.ini. You can also load a module dynamically in your script using dl. The DLLs for PHP extensions are prefixed with php_. Many extensions are built into the Windows version of PHP. This means additional DLL files, and the extension directive, are not used to load these extensions. The Windows PHP Extensions table lists extensions that require, or used to require, additional PHP DLL files. Here's a list of built in extensions (updated PHP 5.0.4): BCMath, Caledar, COM, Ctype, DOM, FTP, LibXML, Iconv, ODBC, PCRE, Session, SimpleXML, SPL, SQLite, WDDX, XML and Zlib. The default location PHP searches for extensions is C:\php5. To change this setting to reflect your setup of PHP edit your php.ini file:
The following table describes some of the extensions available and required additional dlls.
Command Line PHP on Microsoft WindowsThis section contains notes and hints specific to getting PHP running from the command line for Windows.
Getting PHP to run from the command line can be performed without making any changes to Windows. C:\PHP5\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3 But there are some easy steps that can be followed to make this simpler. Some of these steps should already have been taken, but are repeated here to be able to provide a complete step-by-step sequence.
Following these steps will allow PHP scripts to be run from any directory without the need to type the PHP executable or the .PHP extension and all parameters will be supplied to the script for processing. The example below details some of the registry changes that can be made manually. Example #24 Registry changes Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.php] @="phpfile" "Content Type"="application/php" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile] @="PHP Script" "EditFlags"=dword:00000000 "BrowserFlags"=dword:00000008 "AlwaysShowExt"="" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\DefaultIcon] @="C:\\PHP5\\php-win.exe,0" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell] @="Open" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open] @="&Open" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open\command] @="\"C:\\PHP5\\php.exe\" -f \"%1\" -- %~2" With these changes the same command can be written as: "C:\PHP Scripts\script" -arg1 -arg2 -arg3 script -arg1 -arg2 -arg3
|