|
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 have instructions and notes for Apache 1.3.x users on a separate page.
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 #1 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 #2 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 #3 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 |