Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie puzzled by mod-perl

Status
Not open for further replies.

Newposter

Technical User
May 9, 2002
735
US
Installed linux distro with mod-perl selected. Successfully enabled Apache running web site with internal IP address, except .cgi wouldn't run. Checked permissions and AddHandler, all OK; found that PERL path is invalid (default when I ran this script on 3rd party host was /usr/local/bin/perl). This path is empty. What do I need to do to find the path and enable script? What is the difference between installing PERL separately vs mod-perl (bear in mind that I don't know some of these acronyms). Newposter
"Good judgment comes from experience. Experience comes from bad judgment."
 
OK, found the perl command, tested it with hello.pl and it's active. Fixed the shebang and now got this error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, me@domain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Error log in Apache shows:

Premature end of script headers: index.cgi, referer:
So I had read before that the script needed modification as follows:

The .cgi file has at the beginning:

#!/usr/local/bin/perl
print "Content-type: text/html\n";


The "print" line was later in the file, but needed to be moved up to right after the shebang. Note that this script was proven to work on an earlier version of linux from the same company. It had to be modified for the newest version. Thanks to all in this forum and others who helped!


Newposter
"Good judgment comes from experience. Experience comes from bad judgment."
 
Couple things, check out this FAQ on debugging perl/cgi:
I'm not sure if it mentions it, but add this line to the top:
use CGI::Carp qw(fatalsToBrowser);
it wraps standard error in just enough html to report to the browser. Since you have easy access to the logs, it doesn't mean too much. Wont' give you any more info, just in an easier place.

And maybe more to the problem at hand, the mime line has two newlines at the end, don't know if you just had a typo, but it would give you that error:
print "Content-type: text/html\n[red]\n[/red]"; ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Damnedest thing, it worked last night and didn't tonight, and I made no changes. I tried inserting the 2nd line (\n), but no change. I still get the premature end of header message in my error log. Newposter
"Good judgment comes from experience. Experience comes from bad judgment."
 
Try typing at the command line: perl [path to perl file].

For example:

If I wanted to run test.cgi, I would type at the command line:

perl /var/apache/cgi-bin/test.cgi

If it runs without error you will see HTML code on the screen. This means that there is either a problem with the permissions of the file, and apache can't execute it, or that there is a misconfiguration in the httpd.conf file.

If it does not run, then there is a problem with your perl code.

Try copying and pasting this into a file and see if this runs:

#!/usr/bin/perl

#use CGI; #use with web-browser
use CGI qw(-no_debug :standard); #use with command line
use strict;

my $q = new CGI;

print $q->header;
print &quot;<body bgcolor=\&quot;navy\&quot;><font size=\&quot;-2\&quot; color=\&quot;white\&quot;>\n&quot;;
print &quot;<center><h2>Hello World</h></center>\n&quot;;
print &quot;<br> \n&quot;;
exit 0;


That is a pretty straight forward cgi that should say hello world to the browser.
 
Already done, ran a test hello.pl successfully in the /usr/bin/ folder. Still works, but the .cgi in question doesn't, in its folder. Permissions for the entire site are 755, AddHanler is set to use cgi and pl, Options ExcCGI set for that folder, script is a known good one from previous 3rd-party hosting on linux. The only thing I can think of is that I started Sendmail without having configured it, whereas it was inactive before. The script invokes Sendmail. Will comment out that part and try it.

On another note, configuring Sendmail even with Webmin is a nightmare for the newbie. Haven't figured out how to do it. Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
Have you tried the hello.pl from the web? Ie, put it in your cgi-bin directory and see if you can call it from the web browser?
 
Start your script like this and you'll pick up lots of errors:
Code:
#!/usr/local/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;
It'll at least tell you which lines of the perl script it's failing, and should rarely if ever give you an internal server error, assuming apache is set up right and you have no problems with permissions and the interpreter path. Those can be checked, as bpinos said, by running a .cgi hello world script. For more cgi debug help, look at the FAQ's listed above. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
If you post your script that is failing, I will look it over and tell you what's wrong with it.
 
OK, I verified that hello.pl executes from my cgi-bin directory. The apache error log still showed Premature end of script headers for both the hello.pl and my .cgi that won't execute. I have the shebang and content type line in the files.

Permissions are 755. AddHandler and Options are set correctly.

Following icrf's advice, I tried to run the file with the fatals to browser and got errors for every variable in the script:

Global symbol &quot;$cgiurl&quot; requires explicit package name at (file location). Probably a hundred of these lines.

This is a guestbook script that acquires info using cookies and takes info from fields in a form, parses it, pastes it into a .txt file and emails notification to the webmaster. I commented out the email part, but all these other errors are there.

This is a borrowed script, so forgive me if I don't fully understand how every line works. I'd also rather not post it here explicitly for security reasons. I've been hacked too many times.

Can anyone tell me what's wrong? This script did run fine under Redhat 6.2. Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
When use strict; is in the script, you have to declare every variable with my before you use it, example: my $cgiurl; This is good programming practice and it will catch a lot of errors. However, if this is a script that you didn't write and it doesn't comply with the strict pragma, it is probably more work than it's worth to change it (unless you plan on making large changes). Easiest way out is to remove the line use strict; from the script and see what happens. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Thanks, I'll try that tonight. Changing to my $variable did eliminate each error, but I can't rewrite 100 lines. Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top