PHP Doku:: Apache 2.x on Microsoft Windows - install.windows.apache2.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchInstallation und KonfigurationInstallation on Windows systemsApache 2.x on Microsoft Windows

Ein Service von Reinhard Neidl - Webprogrammierung.

Installation on Windows systems

<<Apache 1.3.x on Microsoft Windows

Sun, iPlanet and Netscape servers on Microsoft Windows>>

Apache 2.x on Microsoft Windows

This 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.

Hinweis:

You should read the manual installation steps first!

Hinweis: Apache 2.2 Support

Users of Apache 2.2 should note that the DLL file for Apache 2.2 is named php5apache2_2.dll rather than php5apache2.dll and is available only for PHP 5.2.0 and later. See also » http://snaps.php.net/

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.

Hinweis: Beachten Sie bitte, dass Sie bei Pfadangaben in der Apachekonfigurationsdatei unter Windows alle Backslashes, wie z.B. c:\directory\file.ext, in Schrägstriche umwandeln sollten: c:/directory/file.ext. Bei Verzeichnisnamen kann weiterhin ein abschließender Schrägstrich nötig sein.

Installing as an Apache handler

You need to insert the following lines into your Apache httpd.conf configuration file to load the PHP module for Apache 2.x:

Beispiel #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"

Hinweis: Remember to substitute your actual path to PHP for the C:/php/ in the above examples. Take care to use either php5apache2.dll or php5apache2_2.dll in your LoadModule directive and verify that the referenced file is in fact located at the file path that you point to in this directive.

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 CGI

You 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:

Beispiel #2 PHP and Apache 2.x as CGI

#!C:/php/php.exe
<?php
  phpinfo();
?>

Warnung

Wenn Sie das CGI-Setup verwenden, ist Ihr Server für einige mögliche Angriffe anfällig. Wie Sie sich vor diesen Angriffen schützen können, entnehmen Sie bitte dem Kapitel über CGI-Sicherheit.

Running PHP under FastCGI

Running 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:

Beispiel #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  
Files with a .php extension will now be executed by the PHP FastCGI wrapper.


24 BenutzerBeiträge:
- Beiträge aktualisieren...
pkay(number42) at gmail dot com
30.12.2010 18:31
Running Apache2.2 on Windows 7.  There was no php5apache2_2.dll on my system, and all I got was a message box "The requested operation has failed!" (no, that's not OK).

Finally realized that thread-safe version (VC6, mind!) was necessary - it had the dll in it.

Downloaded that, apache runs with

LoadModule php5_module 'C:/Program Files (x86)/PHP/php5apache2_2.dll'
#etc
farinspace
20.11.2010 20:36
Running PHP under FastCGI:

Besides the following in your httpd.conf

    LoadModule fcgid_module modules/mod_fcgid.so 
    FcgidInitialEnv PHPRC "c:/php"
    AddHandler fcgid-script .php 
    FcgidWrapper "c:/php/php-cgi.exe" .php

Remember to add the following to the default <Directory "C:/apache/htdocs"> block (or virtual host blocks):

    Options ExecCGI
lebovskiy at ua dot fm
17.11.2010 7:59
I install httpd-2.2.17-win32-x86-openssl-0.9.8o.msi and after
php-5.3.3-Win32-VC9-x86.msi on WinXP SP3. PHP installation add to httpd.conf next lines:

LoadModule php5_module "C:/PHP/php5apache2_2.dll
"PHPIniDir "C:/PHP"

After it Apache don`t starts. If remove PHPIniDir line Apache  starts ok, but C:/PHP/php.ini don`t loaded. So you can`t use any extension (for me it's MySQL).

I uninstall VC9 version and install VC6 (php-5.3.3-Win32-VC6-x86.msi) version. All works fine now.
halmai
15.11.2010 12:42
I wanted to install PHP5.3 for Apache2.2 with PostgreSql 9.0 support on WindowsXP. It took me hours to solve it.

The following possible problems occur:
- You should use the VC6-compiled version of php instead of VC9. The later one does not work properly with apache.
- the postgres handler dlls are not working in PHP5.3.

The symptom was a misleading and very confusing error message:

Unable to load dynamic library 'c:\Progra~1\PHP\ext\php_pgsql.dll'

The dll itself was there but when it started to load the other dll (libpq.dll) from the php directory then this caused an error. This error was misinterpreted internally in the above message.

The solution was NOT to use the libpq.dll from php but use it from postgres distribution instead.

For this purpose I inserted the following line into the apache httpd conf:

LoadFile "C:/Progra~1/PostgreSQL/9.0/bin/libpq.dll"

This preloads the dll. When php_pgsql.dll would load his own libpq.dll, then there is the preloaded version of this file in the memory already. This prevents us from using the bad version of dll.

I hope I helped.
terry_513 at yahoo dot com
8.10.2010 17:53
I have installed PHP5.3.3 and Apache2.2.1 successfully on c:/webserver and php on cL/webserver/php. Inidividually both are working.

All manuals show to add loadModule
LoadModule php5_module "c:/webserver/php/php5apache.dll"

with php5apache2.dll or php5apache2_2.dll. But in my PHP folder, I have php5apache.dll.

On setting LoadModule, AddType & PHPIn
LoadModule php5_module "c:/webserver/php/php5apache.dll"
PHPIniDir "C:/webserver/php/"
...
AddType application/x-httpd-php .php

to http.conf, apache2 doesn't work. It pops up "The request has failed". No errors in logs. But apache doesn't work. If I remove these 3 lines, then it works perfectly.

I changed "/" and "\", removed "/" after php in phpini line, but no success. In php.ini file also for setting extension, I had to enter just the "ext" and not full path to make it work.

Can anynoe tell what could be the point, and how to solve it. I am looking badly to setup this and start working. any help is highly appreciative.

Thanks,
Nick
16.06.2010 15:48
After using the Windows installer for Apache 2.2 and PHP 5.3.2, and installing PHP as an Apache module (not CGI), Apache would crash and fail to start. There were two problems with the configuration files for Apache and PHP.

First, make sure your Apache configuration file reads something similar to:

LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"
PHPIniDir "C:/Program Files/PHP/"

While other users have disabled some or all of the MySQL extensions to prevent all three from running at the same time, I have all of them enabled. However, I do not have PostgreSQL, so I needed to comment out loading the php_pgsql.dll in my php.ini file, as follows:

;[PHP_PGSQL]
;extension=php_pgsql.dll

This stopped Apache from crashing and started successfully.
Michael
3.03.2010 18:48
The value for FcgidWrapper cannot contain spaces..

This won't work:
FcgidWrapper "c:/program files (x86)/php/php-cgi.exe" .php

But this will:
FcgidWrapper "c:/progra~2/php/php-cgi.exe" .php
Steve
24.02.2010 1:53
I also had a problem with the PHPIniDir declaration.  This is with Apache 2.2 on XP.  I had to include a final slash, as in PHPIniDir "C:\Program Files\php\".  Apache failed to start if I did not include the slash after php.
Kerry Kobashi
14.12.2009 7:56
If you find that Apache crashes when you attempt to start it, its likely that one of the PHP extensions is the cause. This is likely the case if you use the PHP Windows installer and choose all extensions in the setup program to be installed on disk. Unfortunately, it will also enable all extensions too causing potential problems.

For example, after installing PHP 5.2.11 and Apache 2.2 under Windows XP, Apache kept crashing. This was due to using all three versiosn of mysql extensions attempting to run:

[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
Anonymous
10.12.2009 10:25
If anybody here encounters an error regarding PHPIniDir, change PHPIniDir "C:/php/" to PHPIniDir "C:\php\".
nicolas dot grasset at gmail dot com
7.07.2009 19:08
Here is how I created a silent install for Apache2.2 and PHP5.2.10 on Windows XP (running on a MacBook Pro):

Download Apache2 and PHP5 installer files in a directory and update the msi file names in the following commands.

To have PHP installer find Apache2, do not forget APACHEDIR!

msiexec /i apache_2.2.11-win32-x86-no_ssl.msi /passive ALLUSERS=1 SERVERADMIN=admin@localhost SERVERNAME=localhost SERVERDOMAIN=localhost SERVERPORT=80 INSTALLDIR=c:\apache
msiexec /i php-5.2.10-win32-installer.msi /qn APACHEDIR=c:\apache INSTALLDIR=c:\php ADDLOCAL=ext_php_mssql,apache22
net stop "Apache2.2"
net start "Apache2.2"
CP
16.04.2009 20:27
This is old news to some. But people with Apache 2.0.55 / PHP 5.1.2 might like a reminder before they pull their hair out! (Some of us have ISPs using older version and need to test on a like version before we upload.)

If using PHP 5.1.2, to run Apache as a module, do *not* use Stephan's "php5apache2.dll" from http://www.ApacheLounge.com. That is for pre-5.1.2!

**There is a "php5apache2.dll" included with Windows PHP 5.1.2 zip file by default.**

If you forget this and overwrite the included DLL with Stephan's (as I did) you'll spend hours attempting to escape "DLL hell", with no success.
Anonymous
26.02.2009 15:32
i followed henke37's way to for the httpd.conf

I added all this at the very end of httpd.conf

# For PHP 5
#load the php main library to avoid dll hell
Loadfile "C:\php-5.2.8-Win32\php5ts.dll"

#load the sapi so that apache can use php
LoadModule php5_module "C:\php-5.2.8-Win32\php5apache2_2.dll"

#set the php.ini location so that you don't have to waste time guessing where it is
PHPIniDir "C:\php-5.2.8-Win32"

#Hook the php file extensions
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps

Also i didn't use short open tags as they are disabled in
"php.ini-recommended" if you don't change anything
So use this to test
<?php
 phpinfo
();
?>
NOT
<? phpinfo(); ?> short open tags

added my php directory to the PATH system variable and i start apache manually not as a service

It works for me hope it helps you!
cormac at kernan dot eu
21.04.2008 3:08
All good advice from henke, except where it says "Do not edit the system path".  You will NOT be able to load extensions that have dependencies e.g. MySQL, without adding PHP to your system path.  This threw me for some time as other extensions without dependencies will work without this requirement.
cfoesterle at yahoo dot com
10.02.2008 17:41
I do not have IIS installed on my server, only Apache. So I had to edit the PHP.ini file and comment out (add leading ";") to the following line "extension=php_iisfunc.dll" as I was getting "Faulting application httpd.exe, faulting module php_iisfunc.dll" errors when this line was active. I also added an additional  "AddType application/x-httpd-php .html" to my httpd.conf file so that inline php would work with files ending with an extension of ".html" on my server.
mjm at alum dot mit dot edu
27.01.2008 5:33
If you use the PHP 5 installer, you'll notice that it uses the wrong type of slash on Windows!

Change C:/Program Files/PHP/" to C:\Program Files\PHP\" and everything works great!
packard_bell_nec at hotmail dot com
3.10.2007 5:24
If you install PHP as an Apache CGI binary, you can add:
AddHandler cgi-script .php
into Apache httpd.conf, and add shebang line to every PHP scripts like:
#!php
<?php
phpinfo
();
?>
. But adding shebang line has a disadvantage that if you decided to install PHP as an Apache module afterwards, then the shebang line WILL appear in the web page.
In fact, you do NOT need to add shebang line to every PHP script even if you install PHP as an Apache CGI binary, because you can add:
ScriptInterpreterSource Registry-Strict
into Apache httpd.conf, and make the registry file and merge it like:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.php\Shell\ExecCGI\Command]
@="\"C:\\Program Files\\PHP\\php-cgi.exe\""
. Then you will NOT need to change the PHP scripts which do not contain shebang line.
philippeboucher at newlogiccanada dot com dot com
31.07.2007 23:05
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.
anonymousness
15.06.2007 16:30
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.
charlie at oblivion dot cz
15.02.2007 1:19
..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)
Jim Keller
11.01.2007 2:35
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.
pcdinh at phpvietnam dot net
7.10.2006 12:50
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
PHPIniDir "c:/server/php6"

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.
subajawa at yahoo dot com
4.08.2006 22:56
To install PHP as Apache 2 CGI script, add these lines in addition to the 3 lines mentioned in the document.

<Directory "C:/php">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
Isaac dot Brown at ArvinMeritor dot com
17.05.2005 14: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.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)