Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

HTML::Template / Apache problem.

by DigitalKitty (Parson)
on Dec 28, 2003 at 06:08 UTC ( [id://317282]=perlquestion: print w/replies, xml ) Need Help??

DigitalKitty has asked for the wisdom of the Perl Monks concerning the following question:

Hi.
In experimenting with the HTML::Template module, I have experienced a small problem:

test.tmpl

<html> <head> <title><TMPL_VAR NAME="THAT_FAMOUS_STRING"></title> </head> <body> <b><TMPL_VAR NAME="THAT_FAMOUS_STRING"></b> </body> </html>


test.cgi

#!/usr/bin/perl -w use strict; use lib qw(/home/kmiller/lib/); use HTML::Template; my $that_famous_string = "Hello, World!"; my $template = HTML::Template->new(filename=>'test.tmpl'); $template->param(THAT_FAMOUS_STRING=>$that_famous_string); print "Content-type: text/html\n\n"; print $template->output;

Output when executed from the command line:

Content-type: text/html <html> <head> <title>Hello, World!</title> </head> <body> <b>Hello, World!</b> </body> </html>

When I attempt to execute the program as a url, I receive the dreaded 'Internal Server Error' error message. Since I don't have root access, I am unable to read the apache logs. Any idea why the error is occuring? I am using the 'lib' pragma to identify the location of my modules. In order to establish whether or not they were installed correctly, I wrote a small test script:

#!/usr/bin/perl -w use strict; use lib qw(/home/kmiller/lib/); use HTML::Template;

and executed it from the command line without incident.
Thanks,
-Katie.

janitored by ybiC: Balanced <readmore> tags around example code sections

Replies are listed 'Best First'.
Re: HTML::Template / Apache problem.
by dws (Chancellor) on Dec 28, 2003 at 06:22 UTC
    I wrote a small test script ... and executed it from the command line without incident.

    That puts you ahead of most people who run into this error, and narrows the field significantly.

    If you have access to the server error logs, look there first. If you're having to install modules locally, you might not have access. That sucks, but it's survivable.

    I suspect you're running into an indirect permission error, possibly from   use lib qw(/home/kmiller/lib/); Whatever user Apache is running under might not have individual or group permissions to see into /home/kmiller/lib/. If that's the case, then any modules you have there (e.g., HTML::Template, if you've installed it locally) will be ignored. The resulting failure to locate a module might cause an internal server error. So check permissions, and verify that that directory, and the modules in it, are visible to and readable by whatever user Apache is running as.

Re: HTML::Template / Apache problem.
by bassplayer (Monsignor) on Dec 28, 2003 at 06:34 UTC
    DigitalKitty,

    CGI::Carp might be useful for getting error messages to a place where you can see them. See the section on MAKING PERL ERRORS APPEAR IN THE BROWSER WINDOW. Something like: use CGI::Carp qw(fatalsToBrowser);.

    Without log info I am just guessing, but you might check permissions, ownership, and correct path to perl.

    bassplayer

      Hi.

      dws++ and bassplayer++

      To my surprise, I was able to read the httpd error log. It said 'Premature end of script headers' so I simply changed the 'test.cgi' permissions with the following command:

      chmod 755 test.cgi

      then re-executed the program. It worked perfectly.

      Thanks for the help,
      -Katie.
Re: HTML::Template / Apache problem.
by stvn (Monsignor) on Dec 28, 2003 at 21:07 UTC
    Katie,

    Good to hear that you solved the issue. Although this wouldn't have solved your particular issue, I find that wrapping the heart of a CGI script in an eval block can help while debugging (and prevent trips back and forth to the error log).

    #!/usr/bin/perl -w use strict; use lib qw(/home/kmiller/lib/); eval { use HTML::Template; my $that_famous_string = "Hello, World!"; my $template = HTML::Template->new(filename=>'test.tmpl'); $template->param(THAT_FAMOUS_STRING=>$that_famous_string); print "Content-type: text/html\n\n"; print $template->output; } if ($@) { print "<PRE>$@</PRE>" }

    Especially since HTML::Template tends to make use of exceptions (die()) when it encounters errors. This traps them and spits them out to the browser as opposed to the error log.

    -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://317282]
Approved by exussum0
Front-paged by gmax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found