-2

I am new to CGI. I wrote a very complex module around perl, cgi, html and javascript. And it runs perfectly on command line. But I am not able to run it via browser. I went on debugging line by line from bottom of my script, only to find that the issue was around the HTML::TableExtract module itself. So to make it simple -

# perl -c test.cgi
test.cgi syntax OK

test.cgi

#!/usr/bin/perl

use strict;
use warnings;

use HTML::TableExtract;

print "Content-type: text/html\n\n";
print <<htmlcode;
<html>
<head>
<title>CGI Perl Example</title>
</head>
<body>
<h1>CGI Perl Example</h1>
<p>CGI Perl Example</p>
</body>
</html>
htmlcode

This works perfectly on command line. But if I run it via Browser it just doesn't work. However, if I remove "use HTML::TableExtract" it works perfectly fine again - even in browser. The permissions are correctly set to 755.

Can someone please help me understand, what I am missing? And how can I fire it up from browser. How can I go about debugging this - My browser redirects me to page not found if I mention use HTML::TableExtract.

Note: Would like to point out one thing, this may be related to setting up some environment variable around HTML::TableExtract. When I first installed the module, there was an error which my hosting administrator helped resolve.

# ./test.cgi
Content-type: text/html

<html>
<head>
<title>CGI Perl Example</title>
</head>
<body>
<h1>CGI Perl Example</h1>
<p>CGI Perl Example</p>
</body>
</html>
AnFi
  • 10,493
  • 3
  • 23
  • 47
Abhi
  • 9
  • 1
  • 6
  • Is it possible that since I asked my hosting administrator to install the module, (as i was facing issues), he probably did it with some access that allows this module to be accessible to me but not by other means ... cgi ... I think the issue is on those lines ... but I am unable to nail it ... – Abhi Sep 26 '15 at 13:52
  • http://stackoverflow.com/a/2165040 – mob Sep 26 '15 at 15:57
  • 2
    What do you mean by "doesn't work"? What does your server error log say? – Schwern Sep 26 '15 at 19:47

1 Answers1

2

Debugging perl CGI scripts

Add use CGI::Carp; to you script to make it report bugs to browser
[It produces http reply over STDOUT instead of default text over STDERR]

Most likely scripts executed from command line and from web server search for modules in different places e.g. due to different settings of PERL5LIB or PERLLIB environment variables.


WARNING

CGI::Carp may be a security threat in "production" version of cgi scripts.
It may provide crucial information to (potential) hackers.

AnFi
  • 10,493
  • 3
  • 23
  • 47
  • Ok ... That's a great start. The site redirects were not allowing me to debug the issue at all. So here is the output on browser now ... when I followed your advice. And it can't find the module. Can't locate HTML/TableExtract.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at test.cgi line 9. BEGIN failed--compilation aborted at test.cgi line 9. – Abhi Sep 26 '15 at 14:12
  • How can I make this right ... for I have this installed pretty much correctly. Why calling it from CGI doesn't allow it to figure out and locally i can compile without issues? – Abhi Sep 26 '15 at 14:18
  • # echo $PERL5LIB /home3/specucs3/perl5/lib/perl5 and PERLLIB is not set ... any hints what needs to be done? – Abhi Sep 26 '15 at 14:39
  • Ok .. I got it working with - use lib ; But just wondering .. if this is the standard way ... – Abhi Sep 26 '15 at 14:46
  • CGI::Carp may be considered as a security threat in "production" version of cgi scripts. It may provide too much informations to (potential) hackers. Its use makes perfect sense in development/debug environment. – AnFi Sep 26 '15 at 15:16
  • @Abhi If you want to be able to install modules without root permissions you either A) compile your own Perl in your home directory or B) [install libraries](https://github.com/miyagawa/cpanminus) in your home directory. *A* is the best in the long run, you get full control and you can't mess up the system Perl. [perlbrew](http://perlbrew.pl/) makes this easy. – Schwern Sep 26 '15 at 19:51
  • Got it ... Thanks a ton. – Abhi Sep 27 '15 at 15:23