Windows上のApacheでFastCGIを動かすメモ


自分用のメモ。


cf. Windows + Apache + FastCGI - h4yの日記
cf. WindowsでRuby on Rails その4 Ruby on RailsをFastCGIで動かす - 色々な事を忘れないよう忘備録と日記


FastCGIのダウンロードは公式サイトダウンロードコーナーから。Apache のバージョンが 2.0.63 なので mod_fastcgi-2.4.2-AP20.dll をダウンロードした。これを mod_fastcgi.dll にリネームして,Apache の modules ディレクトリにコピー。

つぎは Ruby 側の準備。gem で fcgi をインストールしようとしたけど ruby のヘッダファイルがないって怒られる:

 ^o^ >gem install fcgi --remote
 Building native extensions.  This could take a while...
 ERROR:  Error installing fcgi:
         ERROR: Failed to build gem native extension.
 
 C:/usr/ruby/bin/ruby.exe extconf.rb install fcgi --remote
 can't find header files for ruby.
 
 
 Gem files will remain installed in C:/usr/ruby/lib/ruby/gems/1.8/gems/fcgi-0.8.7
  for inspection.
 Results logged to C:/usr/ruby/lib/ruby/gems/1.8/gems/fcgi-0.8.7/ext/fcgi/gem_mak
 e.out

ググってみると,RubyForApache というのが見つかったので version 1.3.1 をダウンロード。なんか2005年って古いんだけど。
ファイルはインストーラなのでダブルクリックしてインストール。途中でインストールするコンポーネントを聞かれるので,mod_fastcgi 以外のコンポーネントのチェックをはずす。mod_rubymysql.soは今回はパス。
あと C:\Windows\System32\msvcp71.dll に書き込めないというメッセージが出るけど,これは無視して進める。


最後に Apache の設定。httpd.conf につぎの行を追加する。

 LoadModule fastcgi_module modules/mod_fastcgi.dll
 AddHandler fastcgi-script .fcgi

Apache を再起動して終了。


テスト用のスクリプトはこんなの。

 #! C:/usr/ruby/bin/ruby.exe
 
 require 'fcgi'
 
 FCGI.each_cgi do |cgi|
   print "Content-Type: text/plain\n\n"
   print "Hello world. This is FastCGI.\n"
 end

それと ExcecCGI を有効にしておく必要があるみたいなので .htaccess で設定する。

 Options +ExecCGI