mod_perl

提供: ArchWiki
ナビゲーションに移動 検索に移動

プロジェクトのホームページ より:

mod_perl は Perl プログラミング言語と Apache HTTP Server の強力なパワーを結集します。Perl を使用して Apache を管理し、ウェブページのリクエストに返答することができます。

インストール

mod_perlAUR パッケージをインストールしてください。

設定

Apache のメイン設定ファイル httpd.conf でモジュールをロード:

LoadModule perl_module modules/mod_perl.so

特定のディレクトリで perl を使ってスクリプトを実行

mod_perl モジュールを有効化する方法は2つ存在します:

バーチャルホストを使う

バーチャルホストを追加します。例:

/etc/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost perlwebtest:80>
	Servername perlwebtest
	DocumentRoot /srv/http/perlwebtest
	ErrorLog /var/log/httpd/perlwebtest-error.log
	CustomLog /var/log/httpd/perlwebtest-access.log combined
	<Directory /srv/http/perlwebtest>
		AddHandler perl-script .pl
		PerlResponseHandler ModPerl::Registry
		Options +ExecCGI
		PerlOptions +ParseHeaders
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

/etc/httpd/conf/httpd.conf に作成したバーチャルホストを記述:

Include conf/extra/httpd-vhosts.conf

Options Indexes FollowSymLinks がないことを確認してください。

/etc/hosts に localhost として "perlwebtest" を追加 (yourhostname はマシンのホストネーム):

127.0.0.1	localhost yourhostname perlwebtest

サブディレクトリを使う

メインの設定ファイルに以下を追加:

/etc/httpd/conf/httpd.conf
Alias /perlwebtest/ /srv/http/perlwebtest/
<Location /perlwebtest/>
      AddHandler perl-script .pl
      AddHandler perl-script .cgi
      PerlResponseHandler ModPerl::Registry
      PerlOptions +ParseHeaders
      Options +ExecCGI
      Order allow,deny
      Allow from all
</Location>

ディレクトリの表示で perl を有効化

/etc/httpd/conf/extra/perl_module.conf を作成:

# Required modules: dir_module, perl_module

<IfModule dir_module>
        <IfModule perl_module>
                DirectoryIndex index.pl index.html
        </IfModule>
</IfModule>

そして /etc/httpd/conf/httpd.conf に以下を記述:

# Perl
Include conf/extra/perl_module.conf

テスト

/srv/http/perlwebtestindex.pl を作成:

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "mod_perl now works\n";

apache の httpd.service再起動して設定をリロードしてください。

そして、設定した方法にあわせて、以下のページを開きます: