Perlモジュールをインストールしたい


プランによってはお客様ご自身で Perl モジュールをインストール可能です。

次のプランをご利用中のお客様はご自身で Perl モジュールをインストールしていただけます。

  • レンタルサーバー(ライト、ベーシック、ハイエンド)
  • 共用レンタルサーバー(S12、S22、S32)
  • マネージド専用サーバー(024v、044 R2、044s R2、084s R2、124s R2、164s R2)
  • マネージド専用サーバー(044、044s、084s、124s、164s)
インストール
  • 以下、アカウント名が kir000000 の場合を例にご説明します。
    1. 対象サーバーにSSHログイン
    2. 使いたいモジュールをインストール(ex. Net::Ping::External)
      # cpanm コマンドでインストール
      $ cpanm Net::Ping::External
      !
      ! Can't write to /usr/local/share/perl5 and /usr/local/bin: Installing modules to /home/kir000000/perl5
      ! To turn off this warning, you have to do one of the following:
      !   - run me as a root or with --sudo option (to install to /usr/local/share/perl5 and /usr/local/bin)
      !   - Configure local::lib your existing local::lib in this shell to set PERL_MM_OPT etc.
      !   - Install local::lib by running the following commands
      !
      !         cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
      !
      --> Working on Net::Ping::External
      Fetching http://www.cpan.org/authors/id/C/CH/CHORNY/Net-Ping-External-0.15.tar.gz ... OK
      Configuring Net-Ping-External-0.15 ... OK
      Building and testing Net-Ping-External-0.15 ... OK
      Successfully installed Net-Ping-External-0.15
      1 distribution installed
      ## 自動的に$HOME/perl5 ディレクトリにインストールされる
      $ ls -l
      合計 16
      drwxr-xr-x 2 kir000000 kirusr 4096 11月  7 13:55 bin
      drwxr-xr-x 4 root        root   4096 10月 30 10:14 etc
      drwxr-xr-x 5 kir000000 kirusr 4096 11月  7 13:57 perl5
      drwx-----x 7 kir000000 kirusr 4096 11月  7 10:51 public_html
      ## インストールしたモジュールの確認
      $ ls -la /home/kir000000/perl5/lib/perl5/Net/Ping/External.pm
      -r--r--r-- 1 kir000000 kirusr 13534  4月 13  2014 /home/kir000000/perl5/lib/perl5/Net/Ping/External.pm
      
    実行(コンソール)
    1. 環境変数の登録
      # .bash_profile 作成
      $ vi .bash_profile
      # 内容
      $ cat .bash_profile
      export PERL_CPANM_OPT="--local-lib=~/perl5"
      export PATH=$HOME/perl5/bin:$PATH;
      export PERL5LIB=$HOME/perl5/lib/perl5:$PERL5LIB;
      # パーミッション修正
      $ chmod 600 .bash_profile
      $ ls -la .bash_profile
      -rw------- 1 kir000000 kirusr 128 11月  7 14:10 .bash_profile
      # 読み込み(再ログインでも可)
      $ source .bash_profile
      # 確認
      $ echo $PERL5LIB
      /home/kir000000/perl5/lib/perl5:
      
    2. 実行
      # サンプルプログラム
      $ cat perl.pl
      #!/usr/local/bin/perl
      use Net::Ping::External 'ping';
      my $alive = ping(host => 'localhost');
      print $alive;
      # 実行
      $ perl perl.pl
      1
      
    実行(Web)
    1. 環境変数の登録
      $ cat public_html/perl/.htaccess
      SetEnv PERL5LIB /home/kir000000/perl5/lib/perl5
      
    2. 実行
      # サンプルプログラム
      $ cat public_html/perl/perl-web.cgi
      #!/usr/local/bin/perl
      print "Content-type: text/plain\n\n";
      use Net::Ping::External 'ping';
      my $alive = ping(host => 'localhost');
      #my $alive = ping(host => 'hoge');
      print $alive;
      # パーミッション設定確認
      $ ll public_html/perl/
      合計 4
      -rwxr-xr-x 1 kir000000 kirusr 222 11月  7 14:51 perl-web.cgi
      
    3. 実行結果はブラウザで確認
    評価点数: 0 (0 件の投票)