How to install PHP on Windows
There are two main ways to install PHP for Windows: either manually or by using the installer.
Manual Installation Steps:
Download the PHP zip binary distribution from » PHP for Windows: Binaries and Sources.
There are several different versions of the zip package – chose the version that is suitable for the web server being used:
- If PHP is used with IIS then choose PHP 5.3 VC9 Non Thread Safe or PHP 5.2 VC6 Non Thread Safe;
- If PHP is used with IIS7 or greater and PHP 5.3+, then the VC9 binaries of PHP should be used.
- If PHP is used with Apache 1 or Apache 2 then choose PHP 5.3 VC6 or PHP 5.2 VC6.
Changing the php.ini file
After 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.
- extension_dir = <path to extension directory> – The extension_dir needs to point to the directory where PHP extensions files are stored. The path can be absolute (i.e. “C:\PHP\ext”) or relative (i.e. “.\ext”). Extensions that are listed lower in thephp.ini file need to be located in the extension_dir.
- extension = xxxxx.dll – For each extension you wish to enable, you need a corresponding “extension=” directive that tells PHP which extensions in the extension_dir to load at startup time.
- log_errors = On – PHP has an error logging facility that can be used to send errors to a file, or to a service (i.e. syslog) and works in conjunction with the error_log directive below. When running under IIS, the log_errors should be enabled, with a valid error_log.
- error_log = <path to the error log file> – The error_log needs to specify the absolute, or relative path to the file where PHP errors should be logged. This file needs to be writable for the web server. The most common places for this file are in various TEMP directories, for example “C:\inetpub\temp\php-errors.log”.
- 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 Spec. The IIS FastCGI implementation needs this 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.
- max_execution_time = ## – This directive tells PHP the maximum amount of time that it can spend executing any given script. The default for this is 30 seconds. Increase the value of this directive if PHP application take long time to execute.
- memory_limit = ###M – The amount of memory available for the PHP process, in Megabytes. The default is 128, which is fine for most PHP applications. Some of the more complex ones might need more.
- display_errors = Off – This directive tells PHP whether to include any error messages in the stream that it returns to the Web server. If this is set to “On”, then PHP will send whichever classes of errors that you define with the error_reportingdirective back to web server as part of the error stream. For security reasons it is recommended to set it to “Off” on production servers in order not to reveal any security sensitive information that is often included in the error messages.
- open_basedir = <paths to directories, separated by semicolon>, e.g. openbasedir=”C:\inetpub\wwwroot;C:\inetpub\temp”. This directive specified the directory paths where PHP is allowed to perform file system operations. Any file operation outside of the specified paths will result in an error. This directive is especially useful for locking down the PHP installation in shared hosting environments to prevent PHP scripts from accessing any files outside of the web site’s root directory.
- upload_max_filesize = ###M and post_max_size = ###M – The maximum allowed size of an uploaded file and post data respectively. The values of these directives should be increased if PHP applications need to perform large uploads, such as for example photos or video files.