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

search for in the

Microsoft IIS 7.0 以降> <Microsoft IIS
[edit] Last updated: Fri, 10 Feb 2012

view this page in

Microsoft IIS 5.1 および IIS 6.0

この節では、Internet Information Services (IIS) 5.1 および IIS 6.0 を手動で設定して、PHP を Microsoft Windows XP および Windows Server 2003 で動かす方法を説明します。 IIS 7.0 以降のバージョンを Windows Vista, Windows Server 2008, Windows 7 そして Windows Server 2008 R2 で動かす方法については Microsoft IIS 7.0 以降 を参照ください。

IIS で PHP リクエストを処理するための設定

手動インストールの手順 での説明にしたがって、PHP をダウンロードしてインストールします。

注意:

IIS を使う場合は、非スレッドセーフ版の PHP を推奨します。非スレッドセーフ版は » PHP for Windows: Binaries and Sources Releases. で取得できます。

CGI や FastCGI 固有の設定を、php.ini で以下のように行います。

例1 php.ini での CGI および FastCGI 用の設定

fastcgi.impersonate = 1
fastcgi.logging = 0
cgi.fix_pathinfo=1
cgi.force_redirect = 0

» Microsoft FastCGI Extension for IIS 5.1 and 6.0 をダウンロードしてインストールします。32 ビット版と 64 ビット版があるので、 環境にあわせて適切なパッケージを選びましょう。

FastCGI エクステンションを設定し、PHP のリクエストを処理できるようにするには 以下のコマンドを実行します。"-path" パラメータの値は、 php-cgi.exe の絶対パスに置き換えましょう。

例2 FastCGI エクステンションで PHP リクエストを処理するための設定

cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" ^
-extension:php -path:"C:\PHP\php-cgi.exe"

このコマンドは、拡張子 *.php 用の IIS スクリプトマッピングを作成します。 .php で終わるすべての URL を FastCGI エクステンションで処理するようになります。 また、FastCGI エクステンションでの PHP リクエストの処理に php-cgi.exe を使うよう設定しています。

注意:

この時点で、最低限必要なインストールと設定は完了しました。 これ以降の手順は必須ではありませんが、IIS 上で PHP を効果的に動かすために強く推奨するものです。

匿名化およびファイルシステムへのアクセス

PHP を IIS で使う場合は、FastCGI の匿名化を有効にしておくことを推奨します。 これは、php.ini ファイルの fastcgi.impersonate ディレクティブで設定します。 匿名化を有効にすると、PHP はすべてのファイルシステム操作を IIS 認証で定義したユーザアカウントで行います。 こうしておけば、同じ PHP プロセスを異なる IIS ウェブサイトで共有している場合でも (各サイトで IIS 認証のユーザアカウントを分けておけば) 一方の PHP スクリプトからもう一方のファイルはアクセスできなくなります。

IIS 5.1 や IIS 6.0 のデフォルト設定では組み込みのユーザアカウント IUSR_<MACHINE_NAME> による匿名認証が有効になっています。 つまり、IIS で PHP スクリプトを実行する場合は IUSR_<MACHINE_NAME> アカウントにスクリプトの読み込み権限を付与しなければならないということです。 PHP のアプリケーションからファイルへの書き込みやフォルダ内でのファイルの作成などをする場合は、 IUSR_<MACHINE_NAME> アカウントに書き込み権限が必要となります。

IIS 匿名認証で使うユーザアカウントを設定するには、次のようにします。

  1. Windows のスタートメニューで "ファイル名を指定して実行" を選び、"inetmgr" と入力して "Ok" をクリックする

  2. ツリービューの "Web Sites" ノードにあるウェブサイトの一覧を展開し、 使うウェブサイトの上で右クリックして "プロパティ" を選択する

  3. "ディレクトリセキュリティ" タブを選択する

  4. "Authentication Methods" ダイアログの "User name:" フィールドで設定

IIS 5.1 および IIS 6.0 の匿名認証

ファイルやフォルダのパーミッションを変更するには、エクスプローラあるいは icacls コマンドを使います。

例3 ファイルのアクセス権の設定

icacls C:\inetpub\wwwroot\upload /grant IUSR:(OI)(CI)(M)

IIS のデフォルトドキュメントを index.php にする

ドキュメント名を指定しない HTTP リクエストを受け取ったときには、 IIS のデフォルトドキュメントが使われます。PHP アプリケーションでは、通常は index.php をデフォルトドキュメントとします。 index.php を IIS のデフォルトドキュメントに追加するには、 次のようにします。

  1. Windows のスタートメニューで "ファイル名を指定して実行" を選び、"inetmgr" と入力して "Ok" をクリックする

  2. ツリービューの "Web Sites" ノードを右クリックして "プロパティ" を選択する

  3. "Documents" タブをクリックする

  4. "Add..." ボタンをクリックし、"Default content page:" に "index.php" を入力する

index.php を IIS のデフォルトドキュメントにする

FastCGI および PHP の再利用設定

IIS FastCGI エクステンションで PHP プロセスの再利用を設定するには以下のコマンドを使います。 FastCGI の設定項目 instanceMaxRequests は、 ひとつの php-cgi.exe が何回リクエストを処理すると FastCGI エクステンションがシャットダウンさせるかを表します。 PHP の環境変数 PHP_FCGI_MAX_REQUESTS は、 ひとつの php-cgi.exe プロセスが何回リクエストを処理すると 自分をリサイクルするかを表します。 FastCGI の InstanceMaxRequests で設定した値が PHP_FCGI_MAX_REQUESTS 以下になるようにしましょう。

例4 FastCGI と PHP の再利用設定

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-InstanceMaxRequests:10000

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000

FastCGI のタイムアウト設定

実行時間が長くなる PHP スクリプトがある場合は、FastCGI エクステンションのタイムアウト設定を増やします。タイムアウトに関連する設定項目は ActivityTimeoutRequestTimeout です。 これらの設定に関する詳細は » Configuring FastCGI Extension for IIS 6.0 を参照ください。

例5 FastCGI のタイムアウト設定

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-ActivityTimeout:90

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-RequestTimeout:90

php.ini ファイルの場所の変更

PHP が php.ini ファイルを探す場所は いくつかありphp.ini ファイルのデフォルトの場所を 環境変数 PHPRC で変更することができます。 特定の場所においた設定ファイルを PHP に読み込ませたい場合は、 以下のコマンドを実行します。環境変数 PHPRC には、php.ini ファイルがあるディレクトリへの絶対パスを指定しなければなりません。

例6 php.ini ファイルの場所の変更

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-EnvironmentVars:PHPRC:"C:\Some\Directory\"



Microsoft IIS 7.0 以降> <Microsoft IIS
[edit] Last updated: Fri, 10 Feb 2012
 
add a note add a note User Contributed Notes Microsoft IIS 5.1 および IIS 6.0
bjorn dot tornroth at nettitonttu dot fi 12-Feb-2012 09:45
If you receive:

Input Error: There is no script engine for file extension ".js".

When executing:

cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"

Include the switch:

/e:jscript

Like this:

cscript /e:jscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"

Worked on freshly installed XP Pro ENG SP3(updated).
Anonymous 10-Feb-2012 02:53
I am using Win 2003 Server SP2, IIS 6, Installing PHP 5.3.10 as FastCGI

If you continue to receive FastCGI could not proccess your request - Access Denied Error -5 check to make sure the IIS_WPG Group has Read, Read/Execute permission to the PHP installation directory and is inherited to the php-cgi.exe file.

Also, in researching this problem during my installation, I also found that you should have an entry in the IIS Web Extensions for the php-cgi.exe.
koen dot bauwens at fracarita dot org 08-Sep-2011 12:42
When executing:

cscript %windir%\system32\inetsrv\fcgico
nfig.js -add -section:"PHP" ^
More? -extension:php -path:"C:\PHP\php-cgi.exe"

You get this response:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\WINDOWS\system32\inetsrv\fcgiconfig.js(1348, 5) (null): 0xFFFFFFDF

Then check if in the C:\WINDOWS\system32\inetsrv\fcgiext.ini file the next text is present:

[Types]
php=c:\php\php-cgi.exe

[c:\php\php-cgi.exe]
QueueLength=999
MaxInstances=20
InstanceMaxRequests=10000
IdleTimeout=90
RequestTimeout=90

If not, add it, worked for me!
gsaarenvirta at makeplain dot com 13-Mar-2011 04:49
A note for your reference ... I was getting error 404 "file not found when trying to browse .php" files in \inetpub\wwwroot although .html files worked fine... messed around for hours until I tried this on advice of a friend.

FYI ...

Operating system Windows Server 2003 SP2 x64
IIS v6.0
PHP v 5.3.5 nts windows x86
Microsoft C++ 2008 redistributable
no fastcgi

Followed all the manual PHP configuration instructions very carefully, set php.ini directives, gave appropriate permissions to "IUSR_(machine)", set up web extensions etc. etc.

The final fix that made everything work... renamed 'php.ini' to 'php-cgi-fcgi.ini'

Hope this saves someone hours...
crab dot crab at gmail dot com 18-Nov-2010 11:40
I am using Win 2003 Server, IIS 6, PHP 5.

If you see "You are not authorized to view this page" error when running your PHP page.

Try one more thing:
1. Right-click {C:\php} (or your PHP installation root) and select {Properties}
2. Select {Security} tab and click {Add} button
3. Enter {ComputerName/IUSR_ComputerName} as object name and press {OK}
4. Select {Read & Execute} as permissions
5. Click {Advanced} button and select {Allow inheritable permissions from the parent...} checkbox
6. Press {OK}
Anonymous 12-Oct-2010 01:49
Facts: WinXp Pro, IIS 5.1, add extension ".php" to default web site, Ok button disabled from application configuration mapping after setting the path to executable

Solution: Click inside the textbox after setting the path will enable ok button

Source: http://support.microsoft.com/?id=317948
Anonymous 14-Sep-2010 10:29
i`ve the same trouble after the install php 5.2.14-nts on IIS6 (Win2003Server)- try to open-dialog when php-file is opening...

I`ve to manual add .php in "Application configuration"  ... \system32\inetsrv\fcgiext.dll  (even this option selected in installation - "Script executable")

this solved the problem :)
Neil Plumridge 24-Aug-2010 07:00
Using WinXP/SP3, IIS5.1, I found that following the instructions added the .PHP file association to the 'Web Sites' level in the IIS Manager, but when I tried to access a PHP page my browser tried to download it.  I had to add the same .PHP file association to the 'Default Web Site' configuration too.
joseph dot dew at metso dot com 28-Jun-2010 09:44
Using PHP 5.3.2 non thread safe VC9 I had to copy the php.ini to php-cgi-fcgi.ini otherwise I just got 404 errors.

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