perlアプリケーションをVirtualHost環境で使うときに、ちょっと注意しないといけない点があったのでメモ。
Apacheの設定
VirtualHost環境で使うときには、それぞれの環境ごとで異なる@INCや環境変数を用いなければなりません。そのためにApacheの設定で以下のような設定をVirtualHost内に書いておく必要が有ります。
PerlOptions +Parent PerlSwitches -I/var/www/Sample/current/lib
設定の例は以下。
<VirtualHost *:80>
ServerName sample.saficion.com
DocumentRoot /var/www/Sample/current/public
ErrorLog /var/www/Sample/shared/log/error.log
CustomLog /var/www/Sample/shared/log/access.log common
PerlOptions +Parent
PerlSwitches -I/var/www/Sample/current/lib
Alias /css/ "/var/www/Sample/current/statics/css/"
Alias /images/ "/var/www/Sample/current/statics/images/"
Alias /js/ "/var/www/Sample/current/statics/js/"
<Perl>
$ENV{PERL5LIB} = '/var/www/Sample/current/lib';
$ENV{PLACK_ENV} = 'production';
$ENV{MOJO_HOME} = '/var/www/Sample/current';
use Plack::Handler::Apache2;
Plack::Handler::Apache2->preload("/var/www/Sample/current/script/Sample");
</Perl>
<Location />
SetHandler perl-script
PerlHandler Plack::Handler::Apache2
PerlSetVar psgi_app /var/www/Sample/current/script/Sample
</Location>
<LocationMatch "/(css|images|js|photos)/">
SetHandler None
</LocationMatch>
</VirtualHost>
関連記事
最後に
今回やってみて、PerlOptions +Parentを付け加えるとApacheの動作がどういうふうになるのかという部分がまだ理解できませんでした。もし分かる人が入れば教えていただきたいです。