Last-modified: 2011-12-26 (月) 01:24:42
Apache/mod_perl導入(CentOS)

概要

ソースからインストールしたApacheにmod_perlをインストールします。
Apacheのインストールに関しては、以下のページを参照ください。
ソースから導入

手順

  1. ソースをダウンロードします。
    Everything is expanded.Everything is shortened.
      1
      2
      3
    
    -
    |
    !
    
    # URLは検証時に使用したものです
    # 最新版のURLに変更してください
    wget http://perl.apache.org/dist/mod_perl-2.0-current.tar.gz
  2. 展開します。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    tar zxvf mod_perl-2.0.4
  3. 展開先へ移動します。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    cd mod_perl-2.0.4
  4. makefileを作成します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
    
     
     
     
     
     
     
    -
    |
    !
    -
    
    perl Makefile.PL \
    USE_APXS=1 \
    WITH_APXS=<Apacheルート>/bin/apxs \
    EVERYTHING=1 \
    PERL_USELARGEFILES=0
     
    # WITH_APXSが無効なのか、途中でapxsのフルパスを求められました
    # 入力すると先へ進めます
    Please provide a full path to 'apxs' executable
    (press Enter if you don't have it installed): <Apacheルート>/bin/apxs
  5. ビルド、インストールします。
    Everything is expanded.Everything is shortened.
      1
      2
    
     
     
    
    make
    make install
  6. <Apacheルート>/conf/httpd.confを開きます。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
    
    -
    !
     
    -
    |
    !
     
    -
    !
     
     
     
     
     
     
    
    # mod_perl
    LoadModule perl_module modules/mod_perl.so
     
    # mod_perl
    # 拡張子がpl、cgi、pmのもの全てをmod_perlで実行します
    <IfModule mod_perl.c>
        PerlRequire conf/startup.pl
        # *.plだけでよいかもしれません
        <FilesMatch "\.(pl|cgi|pm)$">
            SetHandler perl-script
            PerlHandler ModPerl::Registry
            PerlSendHeader On
            Options +ExecCGI
        </FilesMatch>
    </IfModule>
  7. <Apacheルート>/conf/startup.plを作成します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
    
    -
    !
     
     
     
     
     
    
    #!/usr/bin/perl
    use APR::Const -compile => ':common';
    use APR::Table ();
    use ModPerl::Registry ();
    use CGI -compile => ':all';
    use CGI::Carp ();
    1;
  8. Apacheを再起動します。
    Everything is expanded.Everything is shortened.
      1
      2
    
    -
    !
    
    # mod_perl組み込み前1.7MB、組み込み後4.9MBでした
    /etc/init.d/httpd restart
  9. 簡単なコードにて動作確認を行います。
    以下のファイルを拡張子plで作成し、公開ディレクトリ内に置きます。
    アクセスしたあとの更新によりカウントアップすればModPerl::Registryで動作しています。
    Everything is expanded.Everything is shortened.
      1
      2
      3
    
     
     
     
    
    print "Content-Type: text/html\n\n";
    $count++;
    print "hello world [$count]";
  10. または、Apacheのログでも組み込まれていることを確認できます。
    Everything is expanded.Everything is shortened.
      1
      2
    
     
     
    
    tail <Apacheルート>/logs/error_log | grep mod_perl
    [notice] Apache/2.2.12 (Unix) mod_perl/2.0.4 Perl/v5.8.8 configured -- resuming normal operations

検証時の環境

参考