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!

Perl-CGI Apache Server Error

Status
Not open for further replies.

timothy

Programmer
Mar 20, 2000
39
US
I am totally new to UNIX, LINUX, Apache and CGI. This is the first time I left the<br>
comfort of Cold Fusion on NT...<br>
<br>
WHAT I DID...<br>
I wrote a Perl script that allows the user to add links to a page from<br>
another (data entry) page.<br>
<br>
THE PROBLEM...<br>
When the user presses the submit button the page DOES update with the new<br>
link, but instead of giving a thank you message I get a Internal Server<br>
Error with no number.<br>
<br>
I KNOW IT's NOT THE PERL SCRIPT (OR DO I)...<br>
I talked to the Internet provider and they agree that the perl script works<br>
but they are not sure why we are getting a server error. I suggested that<br>
the server (Apache) or the OS (LINUX) needed to be configured differently<br>
but the provider doesn't think so since they are not having problems<br>
elsewhere (Good Point).<br>
<br>
SECURITY? NOT IN THIS CASE...<br>
I set all files and directories to 777, 666, and tried some others. Besides<br>
the script does update the page, it's after the page updates that I get<br>
this error.<br>
<br>
It seems that maybe I need to tell the server where to go when it's done<br>
updating the page.<br>
But I checked other perl CGI scripts and they never seem to have anything<br>
other then a print statement with HTML at the end of the process just like<br>
my script.<br>
<br>
THIS IS THE PERL SCRIPT... (second.pl)<br>
#!/usr/bin/perl<br>
<br>
# get form input, split each form field into @pairs array<br>
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});<br>
@pairs = split(/&/, $buffer);<br>
<br>
# clean up each array element<br>
foreach $pair (@pairs) {<br>
($name, $value) = split(/=/, $pair);<br>
$value =~ tr/+/ /;<br>
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;<br>
$value =~ s/\n/ /g; # replace newlines with spaces<br>
$value =~ s/\r//g; # remove hard returns<br>
$value =~ s/\cM//g; # delete ^M's<br>
$FORM{$name} = $value;<br>
}<br>
<br>
# add links to this file<br>
$out = &quot;../test/edit/LegalPicks.html&quot;;<br>
<br>
# open file for append, add links<br>
open(OUT, &quot;&gt;&gt;$out&quot;);<br>
<br>
# This locks the file so no other CGI can write to it at the <br>
# same time...<br>
flock(OUTF,2);<br>
<br>
# Reset the file pointer to the end of the file, in case <br>
# someone wrote to it while we waited for the lock...<br>
seek(OUTF,0,2);<br>
<br>
print OUT 'Other Stuff99'.&quot;\n&quot;;<br>
print OUT &quot;&lt;a href=\&quot;<A HREF=" TARGET="_new"><br>
close OUT;<br>
<br>
print &lt;&lt;EndHTML;<br>
content-type text/html<br>
&lt;html&gt;&lt;head&gt;&lt;title&gt;Thank You&lt;/title&gt;&lt;/head&gt;<br>
&lt;body&gt;<br>
&lt;h2&gt;Thank You!&lt;/h2&gt;<br>
Thank you for your feedback.&lt;p&gt;<br>
&lt;a href=&quot;index.html&quot;&gt;Return to our home page&lt;/a&gt;&lt;p&gt;<br>
&lt;/body&gt;&lt;/html&gt;<br>
EndHTML<br>
<br>
<br>
THIS IS THE DATA ENTRY PAGE...<br>
<br>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;&gt;<br>
<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title&gt; Add Links Form&lt;/title&gt;<br>
&lt;/head&gt;<br>
<br>
&lt;body&gt;<br>
<br>
&lt;form method=&quot;post&quot; action=&quot;../../cgi-bin/second.pl&quot;&gt;<br>
<br>
&lt;table&gt;<br>
&lt;tr&gt;<br>
&lt;td&gt;Type&lt;/td&gt;<br>
&lt;td&gt;&lt;input type=&quot;text&quot; size=&quot;40&quot; maxlength=&quot;40&quot;&gt;&lt;/td&gt;<br>
&lt;/tr&gt;<br>
&lt;tr&gt;<br>
&lt;td&gt;URL&lt;/td&gt;<br>
&lt;td&gt;&lt;input type=&quot;text&quot; size=&quot;40&quot; maxlength=&quot;40&quot;&gt;&lt;/td&gt;<br>
&lt;/tr&gt;<br>
&lt;tr&gt;<br>
&lt;td&gt;Desc&lt;/td&gt;<br>
&lt;td&gt;&lt;textarea name=&quot;requiredMessage&quot; wrap=&quot;VIRTUAL&quot; rows=&quot;15&quot; cols=&quot;50&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;<br>
&lt;/tr&gt;<br>
&lt;/table&gt;<br>
&lt;input type=&quot;submit&quot; name=&quot;addLink&quot; value=&quot;AddLink&quot;&gt;<br>
&lt;/form&gt;<br>
<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
<br>
Any help would be great<br>
<br>
Thanks
 
I don't know if it's going to be this simple, but... You've got code to start off the page output that looks like this:<br>
<FONT FACE=monospace><br>
print &lt;&lt;EndHTML;<br>
content-type text/html<br>
&lt;html&gt;<br>
</font><br>
<br>
Don't you need to have a blank line after the content-type and before the &lt;html&gt;? Also, should the content-type be printed as:<br>
<FONT FACE=monospace><br>
content-type: text/html<br>
</font><br>
ie, a &quot;:&quot; after the &quot;content-type&quot;.<br>
<br>
You might want to take a look at the CGI module that's provided with perl. This provides a lot of functions for dealing with CGI input and HTML output that can save a lot of grief in the long run :)<br>
<br>
&quot;<FONT FACE=monospace>perldoc CGI</font>&quot; should display the perl online manual pages about the module itself.<br>
<br>
Hope this helps.
 
additionally,<br>
( I have not played with FLOCK much, but.....)<br>
it appears that you are trying to 'flock' a file handle that does not exist. The output file you are trying to 'lock' is attached to handle 'OUT'. You then try to lock and seek on handle 'OUT<font color=red>F</font>'. I think the 'open', 'flock', 'seek', 'print', and 'close' need to be operating on the same handle.<br>
<br>
Good Luck
 
Timothy,<br><br>In addition to the missing colon, your print content-type identifier needs to end with at least one blank line so the browser recognizes the end of the header. I'd print it separately, before your print &lt;&lt;EndHtml; line, like this:<br><br>print &quot;Content-type: text/html\n\n&quot;;<br><br>Hope this helps.
 
I have this same problem, and it's not a problem with your perl program. It appears that there's some kind of configuration necessary for Apache to run perl CGI... I can make a simple bash script that prints a web page, and it runs fine in CGI. I can make a perl program that does the same thing, and it won't run under Apache. This same perl program runs fine under Pi3Web on Win95. Perhaps you can only do perl under Apache with mod_perl. I'm going to try that. Bobby Martin <A HREF="mailto:bobbymartin@NOSPAMhotmail.com">bobbymartin@NOSPAMhotmail.com</A>
 
Well, I finally fixed my problem.&nbsp;&nbsp;It seems it was due to a combination of file artifacts from copying the file from a dos file system to a linux file system, and some configuration issues with Apache.<br><br>Here's what I had to do to solve the problem:<br>1) create a new file under linux and type in the exact same script again<br>2) change the script name from *.pl to *pl&nbsp;&nbsp;(notice the lack of a .)<br><br>The reason you have to retype the file (I think) is that in DOS the carriage returns are 0xA 0xD while in Linux they're just 0xA.&nbsp;&nbsp;You will see that manifest as ^M at the end of each line, but even after removing the ^M I still had the problem.&nbsp;&nbsp;The dos-to-unix text conversion utility (don't remember the name offhand) might fix your problem, rather than having to type the file again.&nbsp;&nbsp;After I typed in the new file I diffed it with the old (from DOS) file, and every line showed different even though there were no visible differences in the lines.<br><br>As for the .pl -&gt; pl change, that is because my server returns the output from a .pl file as a .pl file for some reason, instead of as CGI output.&nbsp;&nbsp;I suspect I have my server misconfigured somehow.&nbsp;&nbsp;As a temporary solution, changing the extension from .pl to no extension solved the problem.<br><br>Email me at <A HREF="mailto:bobbymartin@NOSPAMhotmail.com">bobbymartin@NOSPAMhotmail.com</A> if you have any questions or suggestions about my Apache configuration.
 
the dos-to-unix conversion utility is.....<br><b>dos2unix&nbsp;&nbsp;&nbsp;&nbsp;original_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new_name &lt;enter&gt;</b> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Just in case it helps at all, I remember having troubles getting Apache working with CGI on an HP-UX machine due to the ScriptAlias directories not being set up correctly. I presume that the linux version of Apache is configured in the same way and so could cause 404 script/page not found errors.<br><br>Loon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top