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.

Ubuntu で CGI.pm のインストール方法

Last updated at Posted at 2020-06-19

CGI を使う次のプログラムを走らせてみた時、

test_cgi.pl
#!/usr/bin/perl
#
use CGI;
my $qq = new CGI;
print $qq->header(-charset=>"utf-8");
print $qq->start_html(-title=>"Perl CGI のテスト", -BGCOLOR=>'#ffffff'),
    $qq->center($qq->h1('Perl CGI のテスト')),
    $qq->hr,
    $qq->ul(
        $qq->li('Python3'),
        $qq->li('Node.js'),
        $qq->li('Ruby'),
        $qq->li('PHP'),
        $qq->li('Perl')
    ),
    $qq->br,
    $qq->br,
    $qq->a({href=>"https://ekzemplaro.org/"}, "トップページ"),
    $qq->br,
    $qq->br,
    $qq->strong("Jun/20/2020"),
    $qq->end_html;
exit;

以下のようになった時の対策です。

$ ./test_cgi.pl 
Can't locate CGI.pm in @INC (you may need to install the CGI module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at ./test_cgi.pl line 3.
BEGIN failed--compilation aborted at ./test_cgi.pl line 3.

ライブラリーをインストールします。

sudo apt install libcgi-session-perl

再びプログラムを走らせると次のようになります。

$ ./test_cgi.pl 
Content-Type: text/html; charset=utf-8

<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Perl CGI のテスト</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body bgcolor="#ffffff">
<center><h1>Perl CGI のテスト</h1></center><hr /><ul><li>Python3</li> <li>Node.js</li> <li>Ruby</li> <li>PHP</li> <li>Perl</li></ul><br /><br /><a href="https://ekzemplaro.org/">トップページ</a><br /><br /><strong>Jun/20/2020</strong>
</body>
</html>

追加情報

エラーメッセージ

Can't locate Jcode.pm in @INC (you may need to install the Jcode module)

対策

sudo apt install libjcode-pm-perl


エラーメッセージ

```text
Can't locate Image/Magick.pm in @INC (you may need to install the Image::Magick module)

対策

sudo apt install libimage-magick-perl


エラーメッセージ

```text
Can't locate LWP/Simple.pm in @INC (you may need to install the LWP::Simple module)

対策

sudo apt install libwww-perl


エラーメッセージ

```text
Can't locate WWW/Google/PageRank.pm in @INC

対策

sudo apt install build-essential


>```text
sudo cpan
cpan[1]> install WWW::Google::PageRank

モジュールの確認方法

sudo apachectl -M
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?