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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI doesnt work on Apache

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
Hi.
I have a VERY simple CGI script which doesn't appear to work.
Firstly Windows doesnt recognise the .cgi extension, but i doubt it's that.
All the script does is take a string from an inputbox an should display the string on a webpage.
Is there a mistake in my script? :
--------------------------------------------------
#!/usr/bin/perl -w

if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} else {
$in = <STDIN>;
}
print << END;

Content-Type: text/html\n\n

<html>
<body>
<center>
<font size = 20> RESULTS
<br>
name = $in
</font>
</center>
</body>
</html>

END
-------------------------------------------------------
I'm using a POST method, but I don't think that's anything to do with it, as I keep getting a 'Internal Server Error' page from Apache.

I really hope someone can help!
Any and all suggestions welcome!
thanks every1; JoE we are all of us living in the gutter.
But some of us are looking at the stars.
 
Unless it has changed recently, Apache plays at least one mean trick. It actually uses the top/first line of the Perl code to find the perl interpreter. Outside of the Apache context, Win boxes use the file extension to identify executable files. But, Apache (as on *nix boxes) uses the first line. I doubt you have a path like '#!/usr/bin/perl -w' on your win box. Try fixing that first.
If that is the only problem, you're on your way.
If not,...

Then, you might try a brutally simple CGI and make it work. Then, go back to your 'a little less simple' piece of code and the problems will be easier to find/fix.

a brutally simple piece of CGI
Code:
#!c:/perl/bin/perl 
print &quot;Content-type: text/html\n\n&quot;;
print &quot;
<html>
    <body>
      <strong>A Working piece of CGI</strong>
    </body>
</html>\n&quot;;

Make that work and then incrimentally increase the complexity of your code until....... you know the rest. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
goBoating,

Sorry to jump in but the shebang line is correct if that is the right path.

Apache on Windows uses *nix paths unless you specify that the registry must be used instead to interpret the extension.

The following line if commented means that the *nix paths will be used:

ScriptInterpreterSource registry

otherwise if the registry is used then the shebang line is not needed.

Hope this helps Wullie

sales@freshlookdesign.co.uk

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
Hey wullie,

your comments are welcomed. I certainly don't know everything there is to know about apache on win boxes. I am force by my employer to use a Win NT4 box as my desktop. My understanding of apache on win machines is from that context. I don't know how this might work for Win2K or XP.

My previous point is that the path '/usr/bin/perl' really smells like a *nux path. That is a typical *nix path to perl. Most Win boxes don't end up with a 'usr/bin/' dir off of root. They certainly can, but they usually don't. They more frequently look like 'c:/perl/bin/perl' or 'c:/program files/perl/bin/perl' or something similar. That is what makes me suspicious that the path is incorrect in the original script.

On an NT box, the default apache install uses the first line of the code to find the perl interpreter. If the perl interpreter is in the PATH for the machine, the first line can simply be '#!perl'.
If the full path to the interpreter is specified it must be correct. Therefore, I am suspicious that /usr/bin/perl won't work for Oxymoron.

I think. Staighten me out if I'm off, here. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Hi mate,

On windows if you have a slash at the beginning of the path then it assumes the path to be from the root of that drive.

So if #!/usr/bin/perl was used as the shebang in a script located on the C drive, then perl should be located at c:\usr\bin\perl.

The drive letter only needs to be used if perl is located on another drive from the script, otherwise *nix paths should always be used.

The reason I never thought anything about the path is because I have always installed perl to /usr/bin/perl on my servers.

Hope this helps Wullie

sales@freshlookdesign.co.uk

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top