At time of writing this, Apache 2.2 is out. For PHP5 with Apache 2.2, I believe one has to use the module file php5apache2_2.dll. As opposed to php5apache2.dll.
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!
Apache 2.2.x Support: Users of Apache 2.2.x may use the documentation below except the appropriate DLL file is named php5apache2_2.dll and it only exists as of PHP 5.2.0. See also » http://snaps.php.net/
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.
- PHP 4.3.0 or later available at » http://www.php.net/downloads.php.
- the latest stable development version. Get the source code » http://snaps.php.net/php5-latest.tar.gz or download binaries for Windows » http://snaps.php.net/win32/php5-win32-latest.zip.
- a prerelease version downloadable from » http://qa.php.net/.
- you have always the option to obtain PHP through » anonymous CVS.
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.
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.
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. A trailing slash may also be necessary for directories.
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"
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.
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.
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.
Apache 2.0.x on Microsoft Windows
To do a silent install of PHP wich correctly modify the httpd.conf file, you HAVE (I find no other way) to put the directory of the Apache inside the INSTALLDIR's MSI option. the APACHEDIR doesn't seem to work. That's the only way I've make it work. Maybe it's because my Apache is not in the default directory, I don't know, but there is a solution for people who cannot make work the silent install (for those who are told by the php setup that it cannot find the httpd.conf file).
Hope it helps someone.
Verrrrrrrry important note:
If you enable multi-byte strings for your installation of PHP, the extension loaded MUST be the first extension in the list.
Apache, NOR PHP will generate any error messages or warning information in the error log or in system logs about this.
This information needs to be included in the Readme or in the distributed INI files.
The recommended PHP ini's should place extension=php_mbstring.dll at the top of the list of extensions.
I had completely forgotten about this when recently upgrading php on a test server; and almost set out to re-install apache.
I had trouble with the PHPIniDir directive, then I realized that the order of the PHP entries is key.
PHPIniDir is a directive found in the load module for php (e.g., php5apache.dll). Therefore, the PHPIniDir directive must come after the LoadModule directive. Otherwise, Apache has no idea what PHPIniDir is, and your Apache service will not start.
PHP5 and apache2_2on a Win32 PC.
Kept getting blank screen (but could see it it with view source) with test script:
The problem is that the above test script uses short open tags "<?" rather than long ones "<?php" The short ones are not enabled with php.ini-recommended version but are in the php.ini-dist version...
Either change php.ini:
short_open_tag = Off #to On to use the above script
or change the script to:
Easy when you know how.
This is after I checked and rechecked the httpd.conf file according to the FAQs...
As a complete novice with all_things_software, I found the instructions above incomplete, in particular with respect to WHERE to add in the additional lines to the PHP configuration file... they assume a certain amount of knowledge, which left me a bit in the dark. [See "at the foot" below for WHERE...]
In fact configuring the httpd.conf file is a piece of cake with the right instructions. This site below (courtesy of my brother-in-law - credit where it's due) gave me the answer, and I have pasted the key information below (permission not granted but credit again due via URL to respective site)
I quote "Next step is to open up your httpd.conf file in a text editor, wordpad or notepad, and add a few lines. The file, from the default installation is found in the X:\Program Files\Apache Group\Apache2\conf folder.
Do a search for "LoadModule" and you will see a list of modules that Apache tries to initiate when starting up. At the foot of this section, add the following 4 derivatives - each on a separate line: LoadModule; PHPIniDir; AddType; second AddType.
LoadModule php5_module "X:/Program Files/Apache Group/php/php-5.2.0-Win32/php5apache2.dll"
PHPIniDir "X:/Program Files/Apache Group/php/php-5.2.0-Win32"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
That's it. Left-click the Apache monitor icon that should be in your task-bar and press restart. You can create a php page to test if the installation has worked. Save the following as info.php in your X:\Program Files\Apache Group\Apache2\htdocs folder assuming you haven't modified your document root." [For "the following" you will have to refer to the site...]
It really was as simple as that... Hope this helps.
..try to set the extension_dir in php.ini to the absolute path.. (when you are pretty sure that you have set the PHPIniDir the right way)
it's important to note that on Apache 2.2.3 (probably other 2.x versions as well) on Windows, the PHPIniDir directive must use forward slashes to delimit directories, not the backslashes commonly used for Windows path strings. If PHP seems to be ignoring the directive, this may be why.
Apache 2.2.3 and PHP 5.2
# For PHP 5 do something like this:
LoadModule php5_module c:/php/php5apache2_2.dll
AddType application/x-httpd-php .php
# configure the path to php.ini
Remember to substitute your actual path to PHP for the c:/php/ in the above examples.
PHP 6 is under active development but for those whose want to try out the new features or just want to keep updated with the development progress of PHP 6.0, you can follow my instructions below to install it on Windows XP and Apache 2.2.3
# For PHP 6 do something like this:
LoadModule php5_module "c:/server/php6/php6apache2_2.dll"
AddType application/x-httpd-php .php
You should change the path as in your system. The directive LoadModule php5_module seems a bit strange to you. It should be LoadModule php6_module instead. However, I have just taken a look at php.internals and came across a message that said it should be changed in the near future after the PHP 5.2 is official released. At the time I write this, PHP 5.2 RC6 is planned to be released in the next few days.
I was also having the 403 forbidden error. Removing the trailing backslash from the script alias as well as adding the following lines solved the issue:
Allow from all
Thanks for the help boss.
Today I try to install PHP5.1.5 with Apache2.2.3 as a module but Apache always cannot start with Windows XP.
After I read the user contributed notes, I found the website Apache Lounge (http://www.apachelounge.com) and got the fixes: php5apache2.dll-php5.1.x.zip (http://www.apachelounge.com/download /mods/php5apache2.dll-php5.1.x.zip).
In the Readme First.txt, Steffen clearly documented the install steps. And it works! Thank you steffen.
To install PHP as Apache 2 CGI script, add these lines in addition to the 3 lines mentioned in the document.
Allow from all
There is a mistake in documentation regarding installation of PHP as Apache 2 CGI script. The ScriptAlias directive should not have trailing slash on 'php' as it then means that 'php' should be part of the URL, just like 'cgi-bin' usually is, and in case of PHP this leads to 403 Forbidden.
Instead, this is the correct directive (no trailing slash on 'php'):
ScriptAlias /php "C:/path/to/PHP/dir"
Indeed the references to "apachelounge" are a lifesaver!
With regards to installation :
Apache 2.2.2 and php v5.1.2 / 5.1.3 / 5.1.4
Excellent site for these installation issues.
If you use Apache 2.2.x, the included DLLs (php4apache2.dll and php5apache2.dll) will not work for you as they are specific to the Apache 2.0.x API. There is an open bug report to address this issue but if you can't wait then go to the following URL and download an appropriate DLL for Apache 2.2.x:
The PHP Group does not endorse this site but it appears useful, so use it :-)
I had a hard time to install PHP5.1 with Apache2.2 as a module, because whenever I tried to start apache, I always got the error that "Cannot load C:/php/php5apache2.dll into server: The specified module could not be found."
I have checked that php5apache2.dll does in the right directory of "c:/php/", and I have also tried to copy some files (php5ts.dll, php.ini) into relevant directories, such as WINDOWS/, Apache2/, but none of them worked.
I then found a post http://www.apachelounge.com/forum/
and tried as suggested by downloading a zip file created by Steffen, and followed the instructions. The apache2.2 now works fine.
BTW, I am using a XP home and folllowed the instructions on the top part of this page.
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.
"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.
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/"
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
BTW I use Win9x to develop but it's not a production server. And yes, adding a trailing slash to the PHPIniDir directive helps.
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.
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.