end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

ActivePerl for win で mod_perl for apache 2.2

これまで、ActivePerl for win では mod_perl は動作しないと思っていましたが、CodeZineでActivePerl for winのmod_perl導入手順が紹介されていました。

http://codezine.jp/article/detail/1449

どうやらwindows環境のmod_perlは、apache2.2のみで動作するようですが、今回は、mod_perl for apache2.2 win の導入方法を紹介します。

mod_perl for win は theoryx5.uwinnipeg.ca から install

mod_perlはデフォルトのppmリポジトリには存在せず、theoryx5.uwinnipeg.ca (※) にある為、ここをリポジトリとして追加すれば、installできます。(ppmリポジトリへの追加手順は次のエントリをご覧下さい。)

http://d.hatena.ne.jp/end0tknr/20081129/1227949162

http://theoryx5.uwinnipeg.ca/ppms/package.xml

リポジトリ追加ができれば、他のモジュールと同様の手順でinstallできます。
尚、mod_perlのinstallの過程で apacheのmoduleのディレクトリを指定する必要がありますが、私の場合、apacheを c:/ApacheGroup/Apache22 にinstallしています。

ppm> search mod_perl
Downloading ActiveState Package Repository packlist...not modified
1: mod_perl
   Embed a Perl interpreter in the Apache/2.2 HTTP server
   Version: 2.0.4
   Author: Philippe M. Chiasson <gozer@cpan.org>
   Provide: APR version 0.009
   Provide: APR::Base64 version 0.009
   Provide: APR::Brigade version 0.009
<略>
ppm> install 1
Downloading mod_perl-2.0.4...done
Unpacking mod_perl-2.0.4...done
Generating HTML for mod_perl-2.0.4...done
Updating files in site area...done
Downloading mod_perl-2.0.4 install script...done
Running mod_perl-2.0.4 install script...
The Apache2 module mod_perl.so is needed to complete the installation,
and should be placed in your Apache2 modules directory. I will
now fetch and install this for you.

Fetching http://theoryx5.uwinnipeg.ca/ppms/x86/mod_perl.so ...  done!
Where should mod_perl.so be placed? [D:/Apache2/modules] c:/ApacheGroup/Apache22
/modules
mod_perl.so has been successfully installed to c:/ApacheGroup/Apache22/modules.
To enable mod_perl, put in the directives
   LoadFile "C:/Path/to/Perl/bin/perl58.dll"
   LoadModule perl_module modules/mod_perl.so
in httpd.conf. For more information, visit
   http://perl.apache.org/
and especially see
   http://perl.apache.org/docs/2.0/rename.html

done
 403 files installed
ppm>

httpd.confの設定

mod_perlを有効にするには、httpd.confに次の内容を追加し、apacheを再起動すれば完了です。

<IfModule mod_perl.c>
AddHandler perl-script .cgi
PerlRequire "c:/ApacheGroup/Apache22/conf/startup.pl"
PerlHandler ModPerl::Registry
PerlSendHeader On
LoadFile "C:/Perl/bin/perl58.dll"
</IfModule>

特にperlのlibを追加する必要がある場合、PerlRequire でperl scriptを実行し、次のように use lib を行ってください。

#!c:/Perl
use lib qw (c:/ApacheGroup/htdocs/wiki3_5_10/lib);
1;

mod_perlの動作確認を行う

mod_perl環境では動作速度の違いが明らかに違うので、mod_perlが有効になっていることを体感できますが、詳細に確認したい場合は、次のような記述をhttpd.confに追加すると、/perl-status (例えば http://localhost/perl-status)mod_perlでcacheされているmoduleを確認できます。

<Location /perl-status>
SetHandler perl-script
PerlHandler Apache2::Status
</Location>

Loaded Moduleを選択すると、次のように表示されます。