1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Windows+Apache+perlで #!/usr/bin/perl なCGIを動かす

Posted at

これまで、WindowsではActivePerlを使っていました。
でも今は Strawberry Perl のほうがいいみたいなので乗り換えました。

Perlのスクリプトのshebang行は通常
#!/usr/bin/perl
にしてますよね。Apacheはこれを読んで /usr/bin/perl を起動しようとするので、Windowsでもこのパスで perl.exe が起動するようにしないとCGIが動きません。

ActivePerlを使っていたときは、ActivePerlの bin フォルダにpathを通したうえで、ActivePerlの perl.exe を C:\usr\bin フォルダにコピーすればOKでした(コピーではなくシンボリックリンクでも良かったかも)。

しかし、Strawberry Perl ではそれではダメでした。C:\usr\bin に perl.exe をシンボリックリンクしてbash等から /usr/bin/perl script.pl を実行するとエラーなく動くのに、なぜかApacheでは 500 Internal Server Error になります。

で、いろいろ試行錯誤してたどり着いたのが、ApacheのScriptInterpreterSourceディレクティブを使うことでした。これはCGIファイルのshebang行(スクリプト先頭の#!で始まる行)を無視して拡張子のみ(.pl や .cgi)でスクリプトファイルを関連付け実行できるというものです。httpd.conf で対象ディレクトリに ScriptInterpreterSource registry を記述してみたら、無事、Apacheで#!/usr/bin/perlなCGIが動くようになりました。

めでたしめでたし

…が、以下の謎があります。

  • レジストリの設定も関連付けもしなくても動いちゃう。え?なんで?
  • C:\usr\bin\perl はやっぱり無いとダメ。なんで?

ま、動いてるから、いっか…

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?