Perl CGI module not available, having trouble installing

Posted on 2003-03-19
Medium Priority
Last Modified: 2013-12-15
Running Mandrake Linux 9.  I'd think that the CGI module is part of the default perl build, but apparently not.  I am trying to use the CGI module to extract values from a form.  My cgi looks like:

use CGI;
$q = new CGI;
$username = $q->param('username');
$password = $q->param('password');
... MORE CODE ...

When I use the form in the test.html file I get a "500 Internal Server Error".  The apache error logs just say:

[Thu Mar 20 21:08:42 2003] [error] (2)No such file or directory: exec of /var/www/cgi-bin/admin.cgi failed
[Thu Mar 20 21:08:42 2003] [error] [client <IP ADDR>] Premature end of script headers: /var/www/cgi-bin/admin.cgi

So, I cant find anything wrong in my script, so I run the script through the console.  

$ perl -D admin.cgi
Recompile perl with -DDEBUGGING to use -D switch
Can't locate CGI.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at admin.cgi line 11.
BEGIN failed--compilation aborted at admin.cgi line 11.

This gives me the impression that I don't have the CGI module (regardless of the fact perl is not compiled corectly for debugging).  So I look in </usr/lib/perl5/vendor_perl/5.8.0> and there is a CGI/ dir, but the dir is empty.  So first I go to mirror that has Mandrake RPMs.  I get "perl-CGI-2.810-3mdk.noarch.rpm" and run it.

# rpm -i perl-CGI-2.810-3mdk.noarch.rpm
error: unpacking of archive failed on file
/usr/lib/perl5/vendor_perl/5.8.0/CGI.pm;3e7a714c: cpio: MD5 sum mismatch

So now I am pretty much clueless, so I try going to www.cpan.org and downloading "CGI.pm-2.91.tar.gz".  So I think maybe this will work so I give is a shot.  

# gunzip CGI.pm-2.91.tar.gz
gunzip: CGI.pm-2.91.tar.gz: invalid compressed data--crc error
gunzip: CGI.pm-2.91.tar.gz: invalid compressed data--length error

SOOOO... Is anyone else as baffled as I am?  Anyone's insight would be helpful!

Matthew Brainard
Question by:brainarm38802

Expert Comment

ID: 8172082
Its like some download problem. Download from here and try.

Author Comment

ID: 8176428
Ok, I got the CGI package installed simply by copying the "CGI.pm" file and all files in "CGI/" to </usr/lib/perl5/vendor_perl/5.8.0/[CGI/]>.  And when I run the script through the command line, it works fine (no errors that is).  But still when I run it through the browser I still get the "500 Internal Server Error", the logs look like:

[Fri Mar 21 14:41:34 2003] [error] (2)No such file or directory: exec of /var/www/cgi-bin/admin.cgi failed
[Fri Mar 21 14:41:34 2003] [error] [client] Premature end of script headers: /var/www/cgi-bin/admin.cgi

Now I cant quite figure out why.  My html file is:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="/javascript/common.js" name="common">

<div align="center">
  <hr noshade>
  <h3 align="left">Administrator Login</h3>
  <div align="left">
    <form action="/cgi-bin/admin.cgi" method="post" name="acctreq" id="acctreq" onSumbit="verifyRequired()">
      <input type=hidden name="subject" value="Account Request">
      <table width="80%" border="0" cellspacing="0">
          <td width="38%">Username:</td>
          <td width="62%"><input name="username" type="text" id="username" size="10" maxlength="8"></td>
          <td> Password:</td>
          <td><input name="password" type="password" size="10" maxlength="16"></td>
          <td colspan="2"><div align="center">
              <input type="submit" name="Submit" value="Submit">
              <input name="Reset" type="reset" id="Reset" value="Reset">
  <p align="left">&nbsp;</p>

And my CGI script is:

use CGI;
$q = new CGI;
$username = $q->param('username');
$password = $q->param('password');
if (($username == "brainarm") && ($password == "test")) {
  print "Content-type: text/html\n\n";
  print "<html>\n<head>\n<title>Administator's Only</title>\n<\head>\n<body>\n";
  print "<center>\n<h1>deljvs-mweb.treca.org</h1>\n<p><hr><p>\n";
  print "<h3>Administrator View: $username</h3>\n</center>\n";
  print "</html>";
} else {
  print "Content-type: text/html\n\n";
  print "<html>\n";
  print "<i>Access Denied!  Press your browser's \"back\" button to try again.</i>\n";
  print "</html>";

Any suggestions?  I dont know why I am getting an error!

Matthew Brainard
LVL 15

Expert Comment

ID: 8180032
hi Matthew,

DOes you scripts run from command line,

ie doing

perl /var/www/cgi-bin/admin.cgi

did produce a correct http header, and not errors.

LVL 51

Accepted Solution

ahoffmann earned 375 total points
ID: 8183965
either your script has not the propper permissions
  1) x bit
  2) execute and read permission for user running web-server
or it's the common hashbang problem, means
  the very first line does not give a valid perl executable
or you have returns in your file, in particular at end of very first (hashbang) line.

Check all these ...

Author Comment

ID: 8196687
ok, I want to thank Chester_M_Ragel.  He suggested I try a new download site.  That got the CGI module on my box.  

But it was ahoffmann that answered my scripting question.  What the problem was, the file was a dos file.  So it was creating line breaks after all of them, including the hashbang.  

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back to our beginners guide of the popular Unix tool, cron. If you missed part one where we introduced this tool, the link is below. We left off learning how to build a simple script to schedule automatic back ups. Now, we’ll learn how to se…
This article explains how to use the rsync command to create backups and sync data across hosts. Rsync is a very useful command that is often used to copy data, make backups, migrate hosts, and bridge the gap between site staging and production envi…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question