PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<Apache 1.3.x on Microsoft WindowsSun, iPlanet and Netscape servers on Microsoft Windows>
view the version of this page
Last updated: Sun, 26 Mar 2006

Apache 2.0.x on Microsoft Windows

This section contains notes and hints specific to Apache 2.0.x installs of PHP on Microsoft Windows systems. We also have instructions and notes for Apache 1.3.x users on a separate page.

Note: You should read the manual installation steps first!

Warning

We do not recommend using a threaded MPM in production with Apache2. Use the prefork MPM instead, or use Apache1. For information on why, read the related FAQ entry on using Apache2 with a threaded MPM

You are highly encouraged to take a look at the Apache Documentation to get a basic understanding of the Apache 2.0.x Server. Also consider to read the Windows specific notes for Apache 2.0.x before reading on here.

PHP and Apache 2.0.x compatibility notes: The following versions of PHP are known to work with the most recent version of Apache 2.0.x:

These versions of PHP are compatible to Apache 2.0.40 and later.

Apache 2.0 SAPI-support started with PHP 4.2.0. PHP 4.2.3 works with Apache 2.0.39, don't use any other version of Apache with PHP 4.2.3. However, the recommended setup is to use PHP 4.3.0 or later with the most recent version of Apache2.

All mentioned versions of PHP will work still with Apache 1.3.x.

Warning

Apache 2.0.x is designed to run on Windows NT 4.0, Windows 2000 or Windows XP. At this time, support for Windows 9x is incomplete. Apache 2.0.x is not expected to work on those platforms at this time.

Download the most recent version of Apache 2.0.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 two ways to set up PHP to work with Apache 2.0.x on Windows. One is to use the CGI binary 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.

Note: Remember that when adding path values in the Apache configuration files on Windows, all backslashes such as c:\directory\file.ext must be converted to forward slashes, as c:/directory/file.ext.

Installing as a CGI binary

You need to insert these three lines to your Apache httpd.conf configuration file to set up the CGI binary:

Example 6-5. PHP and Apache 2.0 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"

Warning

By using the CGI setup, your server is open to several possible attacks. Please read our CGI security section to learn how to defend yourself from those attacks.

Installing as an Apache module

You need to insert these two lines to your Apache httpd.conf configuration file to set up the PHP module for Apache 2.0:

Example 6-6. PHP and Apache 2.0 as Module

# For PHP 4 do something like this:
LoadModule php4_module "c:/php/php4apache2.dll"
# Don't forget to copy the php4apache2.dll file from the sapi directory!
AddType application/x-httpd-php .php

# For PHP 5 do something like this:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php"

Note: Remember to substitute your actual path to PHP for the c:/php/ in the above examples. Take care to use either php4apache2.dll or php5apache2.dll in your LoadModule directive and not php4apache.dll or php5apache.dll as the latter ones are designed to run with Apache 1.3.x.

Note: If you want to use content negotiation, read related FAQ.

Warning

Don't mix up your installation with DLL files from different PHP versions. You have the only choice to use the DLL's and extensions that ship with your downloaded PHP version.



add a note add a note User Contributed Notes
Apache 2.0.x on Microsoft Windows
james at zeromedia dot co dot nz
14-Apr-2006 07:42
After fiddling around for a while trying to get extensions to load, I realised that I had not set my extension_dir setting correctly.

I found the best way to set this is a full path (i.e. extension_dir = "c:\php5\ext")
raccoon dot lists at gmail dot com
14-Feb-2006 03:19
For those of you having trouble with PHP just displaying source code instead of actually parsing the code AND have checked the AddType directive a gazillion times, you might want to change this option in php.ini:

short_open_tag = Off

Yes, it's turned off by default. This makes the PHP engine only parse scripts that begins with <?php, not the shorter version (<?).

Correct me if I'm wrong, but this feels a little awkward!

Regards
Kim
Devin
03-Feb-2006 06:47
My $0.02:

In trying to set up Apache 2.0/PHP5 on my WinXP Pro machine, I configured PHP using the php.ini-recommended file (aside: enabling mysql and mcrypt).  Adding the PHP5 module to Apache 2.0's httpd.conf caused the server to hang when I tried to request any page, even non-PHP.

My solution: use backslashes in paths instead of forward-slashes.

# Load PHP 5
LoadModule php5_module "D:\web\php5\php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "D:\web\php5\"

After changing that one thing, my phpinfo() test page loaded perfectly!
cppswengr at yahoo dot com
26-Jan-2006 05:57
PHP 5.1 with Apache 2.0 on Windows 2000

Like others I needed to add the trailing "/" to PHPIniDir.

I also found that the only way I could get php.ini to work was by starting with php.ini-dist and making the necessary changes, e.g., to the [mail] section.
chris -dot- chaudruc -at- gmail -dot- co
15-Dec-2005 05:02
This took a while for me to figure out but hopefully it will save some time for others.

Running Apache 2, PHP 5.1.1 on Windows XP and could not get mysql library to load. Extension path was correct in php.ini and the module resided in the correct spot.

Discovered that libmysql.dll in the root php directory needs to be moved to C:\WINDOWS or be included in Windows paths in order for this module to load.

From Zend:
"Some modules depend of other libraries, like MySQL. In this case you need to copy libmysql.dll from your MySQL/bin installation directory to a directory in your PATH, like C:\WINDOWS"

Copied over the file and mysql functionality was enabled.
13-Dec-2005 01:12
There are often strong suggestions that Apache/MySQL/PHP should be set up in the Windows root folder, and dire warnings against using folders with spaces in the name. But as a relatively non-technical user, I hate cluttering my Windows XP root directory with folders that should be under Program Files, and of keeping any documents other than in "My Documents" (even though I agree that MS's folder tree is ugly).

Frankly I've never had any difficulty with Apache and MySQL under Program Files, PHP5 deep in the Apache tree, and all documents under My Docs.. Here are the related Apache 2 config lines I use in case anyone is interested (sorry if there are broken lines):

ServerRoot "C:/Program Files/Apache Group/Apache2"

DocumentRoot "C:/Documents and settings/UserNm/My Documents/Websites"

# PHP 5 module
LoadModule php5_module "c:/Program Files/Apache Group/Apache2/php5/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/Program Files/Apache Group/Apache2/php5/"
msonsuz at example dot com
14-Oct-2005 04:28
When you try apache using the bin directory use the command: apache -n "service_name" -t

Use for service_name the name u used. You can find the service_name also in the system tray
withheld at withheld dot com
06-Aug-2005 04:40
BTW I use Win9x to develop but it's not a production server. And yes, adding a trailing slash to the PHPIniDir directive helps.
psxmrtoad at gmail dot com
04-Aug-2005 12:55
Wait, one says keep 'c:/php/'  (<-- the slash) and the says that the slash causes problems.  which one is it?
Brian Guthrie
02-Jul-2005 09:39
I just wanted to comment that changing
-PHPIniDir "C:/php"
to say this
-PHPIniDir "C:/php/"
made it work for me.
Kurt L
19-Jun-2005 11:01
If you install PHP as an Apache Module, don't try to put any of your PHP Scripts into your Apache cgi-bin directory ... they won't work there.  The PHP Scripts have to be under htdocs directory structure, not cgi-bin.  Only a complete newbie would try this, but I have to admit that I tried it myself and couldn't figure out what was wrong with my configuration.
Isaac dot Brown at ArvinMeritor dot com
17-May-2005 03:59
Some XP machines are having troubles with the PHPIniDir derective not finding the php.ini (or so they think). Directories that do contain a php.ini file are returned as empty and it defaults to the next method of finding php.ini (often C:/windows or C:/winnt).

This is likely caused by read permissions not being set correctly on NTFS file systems, however, it has occurred when no cause could be identified. If setting correct file permissions doesn't work, the easiest way around this problem is moving php.ini to the Apache directory or adding the HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath string to your registry and setting it to the correct directory.
wrowe at apache dot org
11-Apr-2005 03:26
Although the warning above reads "We do not recommend using a threaded MPM in production with Apache2" - ignore that nonsense for Win32.

All Apache/Win32 builds were *always* threaded.  Always choose Apache 2 over Apache 1.3 on Windows - because major portions of Apache 2 were written from the ground up to accept Windows.

Apache 1.3 was never designed for threads or non-posix systems.  For Windows they were squirled in with some rather ugly hacks, which will never enjoy much improvement.
lphuberdeau at phpquebec dot org
14-Feb-2005 05:54
I had to add a trailing slash in the PHPIniDir configuration to get Apache to consider it:

PHPIniDir "C:/PHP/"
tpoetter at uos dot de
16-Jan-2005 12:26
It may be that you added a final slash after any of these directory settings. This helped to keep my server from starting. Simply remove these slashes.

<Apache 1.3.x on Microsoft WindowsSun, iPlanet and Netscape servers on Microsoft Windows>
 Last updated: Sun, 26 Mar 2006
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2006 The PHP Group
All rights reserved.
This mirror generously provided by: Playfuls.com
Last updated: Wed 19 Apr 2006 11:13:08 AM EEST EEST