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

linking to perl in xampp apache cgi

Status
Not open for further replies.

PROFESSORSPARKIE

Instructor
Oct 24, 2002
181
US
Can anyone help me with the following cgi(perl) program execution? I submitted it in the perl threads with no response. I am retrying here for help.

It seems there is a lot less participation on some threads lately.

Here is what I am doing.

1. Apache xampp is installed on a Windows XP system.
2. Xampp Control Panel says that Apache is running.
3. I see the Apache icon on the Start Bar.
4. I placed the following HTML file in "C:\apache\htdocs" folder as "SIMPLE.HTML".

<html>
<body>
<h3>
<center>
<TABLE WIDTH=80% BORDER=13 BORDERCOLOR=BLUE>
<TD>
<FORM METHOD="POST" ACTION="simple.pl">
<CENTER>
<TABLE BORDER=1>
<TR> <TD>- REVIEW THE COMPLETE INVENTORY FILE STATUS. -</TD></TD>
</TABLE>
<BR>
<INPUT TYPE="SUBMIT" VALUE="CLICK TO DISPLAY ALL OF THE RECORDS">
</CENTER>
</FORM>
</td>
</table>
</center>
</body>
</html>

5. I placed the following cgi(perl) file in "C:\apache\htdocs" folder as "SIMPLE>PL".

#!"\xampp\perl\bin\perl.exe"

print "Content-Type: text/html\n\n";#!/usr/bin/perl
#**********************************************************************
#* THIS PROGRAM READS THE STANDARD INPUT AND THEN *
#* LISTS OUT A TEXT FILE & PRINTS TO THE STANDARD OUTPUT *
#**********************************************************************
print "<HTML><HEAD><TITLE>Here comes a listing!\n</TITLE></HEAD>";
print "<BODY>";
print "<BR>";
if (open(INV_IN, "<c:\\xampp\\htdocs\\INV_RPT.TXT"))
{
# run this listing if open succeeds
}
else
{
print "Cannot open Mydatafile!\n";
exit 1;
}
while(defined($a=<INV_IN>))
{
print $a;
print "<BR>\n";
}
close(Myfile);
print "file Myfile listed.\n";
print "<BR>\n";
print "</BODY></HTML>\n";
exit 0;

THEN:
6. I have placed the files in the same folders.
When I use the latest Mozilla browser to load the "html" web page and execute it the web page loads OK and when I select the <FORM> tag to load & run the perl program I just get a listing of the perl program.

After it failed I did the following and tried to use the "cgi" option.
I placed the same file in "C:\apache\htdocs" folder as "simple.cgi" & updated the <form> tag.
I also placed the perl program as "smple.pl" & "simple.cgi" in the "C:\apache\cgi.bin" folder and restested.

The browser finds the files, the perl interpreter is in it proper location "c:\perl\bin\perl" and in "c:\xampp\perl\bin\perl" but is not executed. I have tried being more & less speciic on the shbang command.

I have tried every combination with no success.

I write, using a cloud hosted web site with similar programs with no problems. The problem is that, the Apache server and/or the browser are not working together to catch the web page ACTION="simple.pl" request and passing it to perl.



Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
 
Hey,

Have you ensured that the Apache httpd.conf Configuration file is set to enable CGI programmes, and that everything else in the config looks good to go?

Chris
 
I am new to Apache but these commands are in the file.

AddHandler cgi-script .pl
AddHandler cgi-script .cgi

I tried different combination s but just got a perl listing.



Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
 
What happens if you just type the URL of the CGI script in the address bar of your browser? Does the script execute, or do you just get a listing?

My guess is that you'll get a listing, and that it's an issue with how the server is configured. Try asking in forum65 instead.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
It does not run, it just lists out.

Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
 
[0] There are things misunderstood in the set up. This gets the basic laid out, though it may not get understood immediately:

[1] You have to have a dedicated directory where the server would "execute" the file without explicitly specifying the host such as perl.exe. It can be under the documentroot, but, most probably it may not be.

[1.1] Suppose you have you documentroot point to:
[tt] c:\apache\htdocs\[/tt]
And it seems that you want the dedicated directory for cgi be:
[tt] c:\apache\cgi.bin[/tt]
(The document suggests a name cgi-bin for the vitual directory. Let's use it for instance) Then in the httpd.conf, you add the ScriptAlias line like this:
[tt] ScriptAlias /cgi-bin/ "c:/apache/cgi.bin"[/tt]

[1.1.1] Even the cgi.bin directory is not under htdocs, virtual-directory-wise, it is still read as a path of this form:
[tt] [/tt]

[1.1.2] In your html form, you submit the form to the cgi like this.
[tt] <form method="POST" action="/cgi-bin/simple.pl">[/tt]
and put the simple.pl into the c:\apache\cgi.bin directory. Once you that, you will either get the desired output or you will be met with Server Internal Error or alike if the .pl is actually containing error during the execution. (You won't get a "request to download the simple.pl" or "Forbidden, permission denied etc...")

[2] If what said in [1] successfully done, you can just as well experimenting using another dedicated directory directly under documentroot, like it seems you wanted to call cgi.bin. In that case, you add another block in the httpd.conf using Directory, like this.
[tt]
<Directory "c:/apache/htdocs/cgi.bin">
Options +ExecCGI
</Directory>
[/tt]
[2.1] And again you can then submit a form to the .pl or .cgi located inside that dedicated directory, like this.
[tt] <form method="POST" action="/cgi.bin/simple.pl">[/tt]
(watch the difference this time cgi.bin there).

[2.2] Within htdocs/cgi.bin, you should not put plain html or other kind of text file for instance in the hope of navigating to the directory to get to them. It would then be forbidden and permission is denied.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top