0
votes

I have been trying to run a simple perl-cgi script on windows 7. This is a simple HTML form with an OK button where clicking on OK button displays some text. But clicking the OK button on the HTML page, instead of executing and displaying perl file's output, the browser starts downloading the script. I have added handler in httpd.conf

AddHandler cgi-script .pl

But this doesn't help. I added the ExecCGI option in the httpd.conf but that didn't help either.

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
    AllowOverride None
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

Here is the perl script being used:

#!C:\Perl\bin\perl
use CGI;

print "Content-type: text/plain","\n\n";
print "<html>","\n";
print "<head>\n\t<title>Server Information Ready</title>\n</head>","\n";
print "<body>","\n";
print "<h1>Server Information</h1>","\n";
print "</body></html>","\n";

And here is the html file:

<html>
<head><title>Server Information</title></head>
<body bgcolor="#EEAA55">
<h3>Please click OK to get the server information</h3>
<hr><pre>
<form action="http://localhost/cgi-bin/ctest/pranav1a.pl" method="post">
<input type="submit" value="OK">
</form>
</hr></pre>
</body>
</html>

I have tried this on chrome, IE and Mozilla. Mozilla and chrome start the perl file download, but IE just displays some weird content on clicking the OK button. How can I make the browser display output of file execution rather than starting the script download ?

PS: I have tried to use shebang line as '#!c:/Perl/bin/perl' which doesn't seem to work either. I am able to see the perl script's output when executed from cmd prompt.

3
did you test this on a live server. localhost may have these issue as you need to configure a lot of options. I would suggest you trying it on a production environmentdefau1t
In httpd.conf, make sure this line is uncommented: LoadModule cgi_module modules/mod_cgi.so Add a ScriptAlias: <IfModule alias_module>ScriptAlias /cgi-bin/ "C:/BitNami/apache2/cgi-bin/"</IfModule> ScriptAliases are essentially the same as Aliases, except that documents in the target directory are treated as applications and run by the server when requested rather than as documents sent to the client.Scavokovich
Since you've decided to use .pl instead of .cgi, you'll need to add this to httpd.conf: AddHandler cgi-script .pl (likely there's already one for the .cgi extension; if not, add it also. And you may want to put your .pl in /cgi-bin instead of the sub-directory ctest.Scavokovich

3 Answers

1
votes

Found the solution: in my case I was using 'localhost' in form action instead of 'localhost:8080'.

<form action="http://localhost:8080/cgi-bin/pranav1a.pl" method="post">
0
votes

How about the +ExecCGI option? Try the + in front of it.

In addition, these is usually a problem with understanding suexec2 (not sure whether suexec2 applies to a Windows platform):

Read the whole page over there. Such problems are not fixable when you do not understand the gross limitations enforced by suexec. Common errors are:

  • wrong permissions on suexec2 executable.
  • CGI script is located in wrong location.

Have you worked through apache.org/docs/2.2/howto/cgi.html#troubleshoot yet?

0
votes

Thanks Scavokovich.

In my case the following line was commented out in the httpd.conf file.

#LoadModule cgi_module /opt/freeware/lib64/httpd/modules/mod_cgi.so

Uncommenting it, and restarting apache allowed the CGI script to run instead of open as a text file.