とりあえずmod_perlを入れてみる。
事前にCPANから、CGI.pmとCompress::Zlibを落としてインストールしておく。そしてCPANからmod_perl2をダウンロード。Apache2にはmod_perl2が必要なので間違えてmod_perl1をダウンロードしないように。
ApacheのDSOを使ってインストールして組み込むようにするパターンでインストール。
perl Makefile.PL MP_APXS=/usr/local/apache/bin/apxs make make test make install
make testでエラーが出るが気にしない。LWPモジュールを入れてればでないのかも。
そしてhttpd.confに下記を追記
LoadModule perl_module modules/mod_perl.soInclude conf/modperl.conf
includeする外部ファイルmodperl.confに下記を記載
Alias /perl/ /usr/local/apache/htdocs/perl/SetHandler perl-script PerlHandler ModPerl::Registry Options +ExecCGI Allow from All PerlSendHeader On
そして、/usr/local/apache/htdocs/perl以下に、test.cgiを作成する
#!/usr/bin/perl -w use strict; print "Content-type: text/html\n\n"; my $counter = 0; for(1..5){ increment_counter(); } sub increment_counter{ $counter++; print "$counter"; }
実行結果は、実行ごとに値がインクリメントされていくのが分かる。なぜ、$counter=0で初期化されないかという疑問が残るが、それはこれから調査。