(lounge mod_fcgid on 2.4.6)windowsでCGIをFastCGIで実行するように設定する
2014/11/22
windows上でPHPをFastCGI実行を行う方法を、
Apache Loungeで提供されているモジュールを元にご紹介します。
Apache Loungeのモジュールを利用すると、
特に迷うことなく簡単にfcgid(FastCGI)の環境を構築することができます。
はじめに
PHPをfcgid(FastCGI)で実行を行う方法は検索するといろいろと出てくるのですが、
どうも書いてある通りに設定してもうまく動かず、
結構な期間、試行錯誤を繰り返してはまってしまっていました。
Apache Loungeの組み合わせで動作確認
そんな時に出逢ったのがこのApache Loungeで提供されている
Apacheと各モジュールのセットでした。
さすがにセットで公開されているだけあって、両方を採用すればしっかりと動くものですね^^
とはいえ、このApacheLoungeをインストールして、
設定方法がわかったことによって、他の組み合わせでもちゃんと動かすことができました。
組み合わせによって動いたり、動かなかったりするこうした仕組みは、
まずは、動くと確証のある組み合わせで動かしてみてから、
実際に使いたい組み合わせを同じ流儀で試す。
それが近道だと私は思います。
ご自分の環境に対してマッチするかは別としてこうした環境もあるということでご紹介します。
環境
- windows: windows 7 Proffesional(32bit)
※windows 7 Ultimate(64bit)で64bitの組み合わせも動作確認済 - apache: Apache 2.4.6(Apache Lounge)
x64: httpd-2.4.6-win64-VC11.zip
x86: httpd-2.4.6-win32-VC11.zip - fast_cgi: mod_fcgid-2.3.9(Apache Lounge)
x64: modules-2.4-win64-VC11.zip
x86: modules-2.4-win32-VC11.zip - PHP: php-5.5.5-Win32-VC11-x86(PHP)
ダウンロード
Apache Loungeでのダウンロードページの
以下の場所からダウンロードが行えます(2013/10/31現在)
http://www.apachelounge.com/download/
ダウンロードに関しては、環境に明記した各バージョンで行っていますので、
以下の各投稿を参考にダウンロードを行ってインストールください。
既存Apacheとは共存可能
Apacheまでインストールしないといけないの?!そう思われたことでしょう。
Apache Loungeの組み合わせに限って動作するといったものではないはずです。
しかし、他の組み合わせで動作するかわからないもので試行錯誤を行うよりは、
動作すると分かっている組み合わせで一度、環境を構築することは近道です。
実際に動作することを確認した後で、
目的とするバージョンに設定を移植すれば、きっといい結果が得られるでしょう。
そこで、既にインストールしてあるApacheはどうするの?ってことになりますが、
以下で、共存させる方法をご紹介しています。
通常、Apacheのメジャーバージョン(2.0.xxxや2.2.xxx)を、
同一PCにインストールすることはインストーラからはできません。
以下の投稿では、その複数メジャーバージョンの共存方法の紹介です。
1つのPC(サーバー)で複数のApacheをインストールして利用する方法
Apache
Apacheのダウンロードとインストールに関しては以下の投稿をご確認ください。
以下の投稿では、win32版(httpd-2.4.6-win32-VC11.zip)でご説明させて頂いております。
(Apache Lounge版)ローカル環境(windows)へのApache設置
PHP
PHPのインストール方法は5.3以降はインストーラ形式ではなくなっています。
PHPのインストール方法については、以下の投稿でご紹介しています。
以下の投稿では、win32版(php-5.5.5-Win32-VC11-x86)でご説明させて頂いております。
ローカル環境へのPHP設置(Ver.PHP 5.5.5)
fcgid(FastCGI)でPHPを動作させる設定
ApacheとPHPのインストールが完了したら、
PHPをfcgid(FastCGI)として実行させるように設定を行います。
とはいえ、Apache Loungeで提供されているモジュールで設定を行えば、
問題なく実行できる環境が構築できるでしょう。
fcgid(FastCGI)モジュールのインストール
モジュールのダウンロードページには、
以下のモジュールが含まれていることが明記されています。
http://www.apachelounge.com/download/
- mod_security-2.7.5
- mod_fcgid-2.3.9
- dbd_modules-1.0.6
- mod_watch-4.3
- mod_view-2.2
- mod_line_edit-1.0.0
- mod_log_rotate-1.00a
- mod_xsendfile-1.0-P1
- mod_bw-0.92
- mod_jk-1.2.37
- mod_websocket
Apache Loungeで提供されている、
モジュールセット(modules-2.4-win32-VC11.zip)をダウンロードし解凍すると、
含まれているモジュールのフォルダが作成されます。
その中から[mod_fcgid-2.3.9 ]フォルダを開き[mod_fcgid.so]ファイルをコピーします。
コピーしたファイルをApacheのインストールディレクトリ内の[\modules]フォルダへコピーします。
モジュールのインストールは以上です。
httpd.confの設定
httpd.conf ・・・fcgid(FastCGI)の設定で億劫になるのがこのタスクではないでしょうか。
何度やってもうまく動いている気がしない。
Apacheすら起動しなくなる・・・そんな作業です。
しかし、Apache Loungeなら答えがそこにあります。
モジュールを解凍した[mod_fcgid-2.3.9 ]フォルダの中をにあるReadMe.txtを開きます。
テキストの中には以下のように記載されています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# Install: - Copy mod_fcgid.so to your apache/modules folder # Add to your httpd.conf: LoadModule fcgid_module modules/mod_fcgid.so # Configuration: - Configuration, see http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html # Upgrading: from mod_fcgid 2.2 see http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#upgrade # Example configuration for php installed in c:\php : FcgidInitialEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;" FcgidInitialEnv SystemRoot "C:/Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:/WINDOWS/Temp" FcgidInitialEnv TMP "C:/WINDOWS/Temp" FcgidInitialEnv windir "C:/WINDOWS" FcgidIOTimeout 64 FcgidConnectTimeout 16 FcgidMaxRequestsPerProcess 1000 FcgidMaxProcesses 50 FcgidMaxRequestLen 8131072 # Location php.ini: FcgidInitialEnv PHPRC "c:/php" FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 <Files ~ "\.php$>" AddHandler fcgid-script .php FcgidWrapper "c:/php/php-cgi.exe" .php </Files> |
この設定にならって、Apacheのhttpd.confに対して設定を行います。
httpd.confの最後に以下を追記します。
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
#Setting by ReadMe.txt LoadModule fcgid_module modules/mod_fcgid.so <IfModule fcgid_module> FcgidInitialEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;" FcgidInitialEnv SystemRoot "C:/Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:/WINDOWS/Temp" FcgidInitialEnv TMP "C:/WINDOWS/Temp" FcgidInitialEnv windir "C:/WINDOWS" FcgidIOTimeout 64 FcgidConnectTimeout 16 FcgidMaxRequestsPerProcess 1000 FcgidMaxProcesses 50 FcgidMaxRequestLen 8131072 FcgidInitialEnv PHPRC "c:/php" FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 # Global Config Example <Files ~ "\.php$>" AddHandler fcgid-script .php FcgidWrapper "c:/php/php-cgi.exe" .php </Files> </IfModule> |
追記が完了したら、Apache Service MonitorにてApacheを再起動します。
エラーが出た場合には、設定を見直します。
phpinfo()の確認
Apacheのcgi-binディレクトリに対して、以下の処理を記述したテキストファイルを用意し、
ファイル名をphpinfo.php(拡張子php以外はファイル名は自由)で保存します。
1 2 3 |
<?php phpinfo(); ?> |
ここで、phpinfo.phpをcgi-binに配置する理由は、
httpd.confファイルに以下の記述が最初から存在している為です。
この358行目の設定は、URL(だけではないが)に「/cgi-bin/」が含まれているときは、
[c:/Apache24/cgi-bin/]に対する要求であると読み替える設定(エイリアス)です。
また[ScriptAlias]として定義することで、
エイリアスの設定とともに対象のディレクトリでスクリプト実行が行える権限を付与しています。
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
<IfModule alias_module> # # Redirect: Allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. The client # will make a new request for the document at its new location. # Example: # Redirect permanent /foo http://www.example.com/bar # # Alias: Maps web paths into filesystem paths and is used to # access content that does not live under the DocumentRoot. # Example: # Alias /webpath /full/filesystem/path # # If you include a trailing / on /webpath then the server will # require it to be present in the URL. You will also likely # need to provide a <Directory> section to allow access to # the filesystem path. # # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. The same rules about trailing "/" apply to ScriptAlias # directives as to Alias. # ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/" </IfModule> |
ブラウザからの表示確認
ブラウザからローカルホストを確認します。
現時点ではDirectoryIndexの設定を行っていないものとして、
ファイル名を含むURLで指定してください。
http://127.0.0.1/cgi-bin/phpinfo.php
以下のようにphpinfoの情報が表示されれば、phpのcgi実行は動作しています。
fcgid(FastCGI)としての動作確認
phpinfoをブラウザで表示した後、
windowsのリソースモニタを確認すると[php-cgi.exe] が表示されているはずです。
通常、CGI実行した際にはこの[php-cgi.exe]が
ブラウザ表示のあとすぐにグレー表示となって[終了済み]と表示されます。
しかしfcgid(FastCGI)として動作している場合にはページ表示後も終了せずに残ります。
また、ブラウザを更新した際にも[php-cgi.exe]が新たに起動されることなく、
既に起動している[php-cgi.exe]にて表示が行われます。
この既存プロセスを利用して実行する仕組みがfcgid(FastCGI)の特徴です。
またfcgid(FastCGI)モジュールを読み込んでいる場合には、
Apache Service Monitorにモジュール名が表示されます。
その他に明確にfcgid(FastCGI)として動作していることを、
確認できる点が見当たらなかったのですが、phpinfoにCreditが表示されます。
FastCGI Process Manager | Andrei Nigmatulin, dreamcat4, Antony Dovgal, Jerome Loyet |
もっと明確に判別できる方法をご存知の方がいらっしゃいましたら、
コメントで教えてください!
Windows は米国 Microsoft Corporation の米国およびその他の国における登録商標です。
登録番号は以下の通りです。
第3333588号、第3351402号、第4197799号、
第4348387号、第4395963号、第4648301号
Windows は米国 Microsoft Corporation の米国およびその他の国における国際登録商標です。
国際登録番号:1135413
Apache,Apache Hadoop,Apache Subversion,Hadoop,HDFS,HBase,Hive,Mahout,Pigは、
Apache Software Foundationの米国およびその他の国における登録商標または商標です。
ApacheソフトウェアはApache Software License (原文)および
Apache License, 2.0 (原文)に基づきOpen Source Initiativeに承認されライセンスされています。
関連記事
-
SWFをAVI・MPGに変換できるFree SWF Converterが残念な結果に。
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
Apacheインストール直後にコマンド画面でエラーが表示された場合の対処法
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
[コンピュータに MSVCR110.dllがない]とApacheMonitor.exeを起動して言われた場合
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
(lounge Apache 2.4.6)ローカル環境(windows)へのApache設置
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
(apache 2.2.25)ローカル環境(windows)へのApache設置
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
Apache2.0.xのhttpd.confを手動で作成する方法
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
Apache2.0.xの初期設定をVBScriptを利用して1発で完了する方法
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
VisualStudio 2005 Trial(評価版)は今でもダウンロードできたのか。
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
include_once(include) は戻り値が返されるの!?
Google or AdMax Promotion(it) 禁断の機能がau公式 …
-
ファイルアップロード上限の変更(PHP phpMyAdmin wordpress)
Google or AdMax Promotion(it) 禁断の機能がau公式 …