PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Sun, iPlanet, Netscape サーバ(Microsoft Windows 用)> <Apache 1.3.x (Microsoft Windows 用)
Last updated: Fri, 10 Oct 2008

view this page in

Apache 2.0.x (Microsoft Windows 用)

このセクションでは、Microsoft Windows 上の Apache 2.0.x で PHP を使用する場合について説明します。 Apache 1.3 で PHP を使用する場合 については別に記載されています。

注意: まず始めに、マニュアルインストールの手順 をお読みください。

注意: Apache 2.2.x のサポート
Apache 2.2.x を利用しているかたも以下のドキュメントを使用できますが、 DLL ファイルの名前を php5apache2_2.dll に読みかえてください。このファイルは PHP 5.2.0 以降にしか含まれません。 » http://snaps.php.net/ も参照ください。

警告

Apache2 の MPM マルチスレッドモードを実運用環境で使用することは推奨されません。 代わりに prefork MPM または Apache1 を使用してください。その理由については、 マルチスレッド版 MPM の Apache2の FAQ エントリを参照してください。

» Apache ドキュメンテーション を参照し、Apache 2.0.x の基本的な事項について理解しておくことを 強く推奨します。また、以下の解説を読む前に、Apache 2.0.x に関する » Windows 固有の情報 についても参照すると良いでしょう。

注意: PHP と Apache 2.0.x の互換性に関する注意
PHP の以下のバージョンは、Apache 2.0.x の最新版での動作が確認されています。

以上のバージョンの PHPは、Apache 2.0.40 以降と互換性があります。
Apache 2.0 SAPI のサポートは PHP 4.2.0 で開始されました。 PHP 4.2.3 は Apache 2.0.39 で動作します。PHP 4.2.3 を Apache の他のバージョンと 組み合わせて使用しないでください。 PHP 4.3.0 もしくはそれ以降のバージョンの PHP を 最新版の Apache2 と組み合わせて使用することが推奨されます。
ここで挙げたバージョンの PHP は、Apache 1.3.x でも動作します。

警告

Apache 2.0.x は Windows NT 4.0, Windows 2000 および Windows XP で動作するように設計されています。現時点では、Windows 9x のサポートは 不完全です。

最新の » Apache 2.0.x と、対応する バージョンの PHP をダウンロードしてください。 マニュアルインストールの手順 を実施したら、引き続き以下のとおり PHP と Apache の設定を行ってください。

PHP を Windows 上の Apache 2.0.x で動作させるには、2種類の方法が あります。一つは、CGI バイナリを使用する方法、もう一つ は Apache モジュール DLL を使用する方法です。どちらの場合も httpd.conf を編集して Apache が PHP を利用できるようにした後、 Apache サーバを再起動する必要があります。

注意: Windows 上で Apache 設定ファイルにパスの値を追加する際、例えば c:\directory\file.ext に含まれるすべてのバックスラッシュは c:/directory/file.ext のように前向きスラッシュに変換する必要があります。 また、ディレクトリを表す際には最後にスラッシュをつけなければなりません。

CGI バイナリの使用

CGI 版のバイナリを使用する場合は、以下の行を Apache 設定ファイル httpd.conf へ追加してください。

例1 Apache 2.0 で CGI 版の PHP を使用する場合の設定

ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php

# PHP 4 の場合
Action application/x-httpd-php "/php/php.exe"

# PHP 5 の場合
Action application/x-httpd-php "/php/php-cgi.exe"

警告

CGI モードで公開したサーバは、いくつかの脆弱性の標的となる可能性があります。 これらの攻撃からサーバを守る方法については、 CGI セキュリティ のセクションを参照してください。

Apache モジュールの使用

Apache 2.0 でモジュール版の PHP を使用するには、 以下の行を Apache 設定ファイル httpd.conf に追加してください。

例2 Apache 2.0 でモジュール版の PHP を使用する場合の設定

# PHP 4 の場合
LoadModule php4_module "c:/php/php4apache2.dll"
# sapi ディレクトリから php4apache2.dll をコピーするのを忘れないこと!
AddType application/x-httpd-php .php

# PHP 5 の場合
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

# php.ini の場所を設定
PHPIniDir "C:/php"

注意: c:/php/ は実際のパスにあわせて修正してください。 LoadModule ディレクティブでは必ず php4apache2.dll または php5apache2.dll を指定します。 php4apache.dll および php5apache.dll Apache 1.3.x 用です。

注意: コンテントネゴシエーションを使用する場合は、 関連の FAQ を参照してください。

警告

バージョンの異なる PHP の DLL ファイルを混ぜて使わないでください。 DLL と PHP 拡張モジュールは、同一バージョンのファイルだけが 組み合わせて使用可能です。



add a note add a note User Contributed Notes
Apache 2.0.x (Microsoft Windows 用)
webssfz at gmail dot com
30-Jun-2008 11:52
@eric dot zhang at rogers dot com:
The line is not necessary since the installer adds these lines to mime.types:
application/x-httpd-php    php
application/x-httpd-php-source    phps
eric dot zhang at rogers dot com
12-Jun-2008 02:44
for me, I have xp, apache 2.2 and php 5.2.6,
to install, just use the installer and choose your modules during installation, and every thing works fine.
After install, I check the httpd.conf and found nothing about "AddType ..." so I assume you don't need it
cormac at kernan dot eu
21-Apr-2008 02: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.
henke at henke37 dot cjb dot net
22-Feb-2008 11:22
Please completely ignore the page contents, it's stale garbage and will just lead to trouble.

Here is how to do it the right way:
Do not copy any php files anywhere
Do not edit the system path
And absolutely do not use the provided cgi directives.

Here is the proper apache directives to load php, preferbly saved as php.conf and included from your main config.

#load the php main library to avoid dll hell
Loadfile "C:\pathtophp\php5ts.dll"

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

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

#Hook the php file extensions, notice that Addtype is NOT USED, since that's just stupid
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
cfoesterle at yahoo dot com
10-Feb-2008 04: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-Jan-2008 04: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!
rene at metalbunny dot net
27-Nov-2007 10:40
Installed Apache 2.2.6 on WinXP Pro SP2 with PHP 5.2.5 as server module (php5apache2_2.dll)...

Thanks to melanie_c_graham's post, I solved my trouble by commenting out the
PHPIniDir "C:/Program Files/PHP/"
in httpd.conf

With this line present, Apache will generate two "Apache has experienced a problem and needs to close" when attempting to shut down the httpd service.

Starting it up is just smooth, but on shutdown it fails - and with the line present, PHP isn't processed; just produces a blank page (not even an error message).
mhfaust at gmail dot com
23-Nov-2007 03:40
My context -- configuring:
- Windows XP/SP2
- Apache 2.2.6
- PHP 5.2.4 (as Apache module)

I had a problem with PHPIniDir (not loading), when setting it this way:
   PHPIniDir "C:\PHP\"

....but it worked when I changed it to:
   PHPIniDir "C:\PHP"

(deleted trailing slash)

-----------
....This seems relevant to the comment from:
Isaac dot Brown at ArvinMeritor dot com
17-May-2005 06:59

...and contradicts the line in the instructions at the top of this page "A trailing slash may also be necessary for directories."
packard_bell_nec at hotmail dot com
03-Oct-2007 04: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.
simon dot schmitt at med dot uni-heidelberg dot de
28-Sep-2007 03:43
Zend and Microsoft today announced FastCGI for IIS6 and higher: I tried it and it works fine.
Heres the link to the documentation: http://www.iis.net/php
newbe
17-Sep-2007 03:24
I very thank Richard about the following because my appache2.2.4 could't load php5apache2.dll all the time. Then, I found the right answer as below! Good luck!

richard dot blockley at googlemail dot com
21-Aug-2007 08:34
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
melanie_c_graham at hotmail dot com
01-Sep-2007 11:40
For some reason, installing Apache and PHP, I could not use this line item:

PHPIniDir "C:/php"

If I used it, my web server would not restart.  I commented the line out, and voila - PHP is installed perfectly (after an hour or two of swearing at it) and Apache is happy again.

I am going to operate under the assumption that since my system is working just fine without this ini redirection that ini redirection is not required for my configuration.

I am running Windows XP Home, Apache 2.2.4, PHP 5.2.4
richard dot blockley at googlemail dot com
21-Aug-2007 11:34
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.
philippeboucher at newlogiccanada dot com dot com
31-Jul-2007 10: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-Jun-2007 03: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-Feb-2007 12: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-Jan-2007 01: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
07-Oct-2006 11: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.
k2wardog at yahoo dot com
06-Sep-2006 03:55
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:

<Directory "C:/php">
   AllowOverride None
   Options None
   Order allow,deny
   Allow from all
</Directory>

Thanks for the help boss.
subajawa at yahoo dot com
04-Aug-2006 09: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>
04-Aug-2006 09:31
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"
12-Dec-2005 11: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/"
withheld at withheld dot com
06-Aug-2005 02: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.
Isaac dot Brown at ArvinMeritor dot com
17-May-2005 01: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 01: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.

 
show source | credits | sitemap | contact | advertising | mirror sites