I am trying to work through an example from CGI101 (Jaqueline Hamilton's book) and my head is getting turned around. I have two files: env.cgi which looks like

#!C:/Perl/bin/perl -wT
use strict;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use CGI::Pretty;
print header;
print start_html("Environment");
foreach my $key (sort(keys(%ENV))) {
print "$key = $ENV{$key}<br>\n";
}
print end_html;

and envform.html which looks like this:

<html><head><title>Test Form</title></head>
<body>
<form action="env.cgi" method="GET">
Enter your text here:
<input type="text" name="sample_text" size=30>
<input type="submit"><p>
</form>
</body></html>

When I type http://localhost/cgi-bin/cgi101/ch03/envform.html into my web browser and hit 'go', I get a 500 Internal Service Error. Both have permissions 755.

I get two lines in C:\Apache2\log\error.log:
[Wed Jul 12 10:13:04 2006] [error] [client 127.0.0.1] C:/Apache2/cgi-bin/cgi101/ch03/envform.html is not executable; ensure interpreted scripts have "#!" first line
[Wed Jul 12 10:13:04 2006] [error] [client 127.0.0.1] (9)Bad file descriptor: don't know how to spawn child process: C:/Apache2/cgi-bin/cgi101/ch03/envform.html


If I go to C:\Apache2\cgi-bin\cgi101\ch03\envform.html and hit 'go', it properly displays the html page, but when I enter text and press the submit button, it displays the contents of the file env.cgi rather than running the script as file:///C:/Apache2/cgi-bin/cgi101/ch03/env.cgi?sample_text=my+text+here.

I'm not sure what I'm doing wrong here, but I think I've got a poor understanding of how env.cgi and envform.html are supposed to work together (which is no fault of the tutorial, but of my head full of bad wiring).

Any explanation would be appreciated.

Thanks.

This isn't strictly an HTML/CSS/JavaScript question: you're posting in the wrong forum.

I'll answer the parts I can: the HTML form submits the contents of the form to whatever page is specified in the "action" property of the "form" tag.

Your Perl script is supposed to then run, outputting a new HTML page containing the contents of the variables just posted.

I think you have a server configuration problem, as it isn't actually "running" the PERL program.

I also think its a server conf problem. It sounds like you are not using your cgi, you are just trying to load the html page. Typically you don't have html in your cgi-bin, from your error it sounds like your server is configured to treat everything in the cgi-bin as an executable... so I'd take the html out.. it easier.

Put your html in the public_html directory (or what ever the public html root of your web server directory is).

Change the action property of your form tag to point to the cgi-bin: i.e. make it: /cgi-bin/cgi101/ch03/env.cgi

now that should work... but if it doesn't then you should open up the file httpd.conf (or what ever this file is called for apache 2 on windows). Hunt down your cgi settings and change the cgi pattern from cgi-bin/* to *.cgi.

This might be easier... or harder... do either or. Doing both won't break your web site... even if its not the problem ;)

now that should work... but if it doesn't then you should open up the file httpd.conf (or what ever this file is called for apache 2 on windows). Hunt down your cgi settings and change the cgi pattern from cgi-bin/* to *.cgi.

This might be easier... or harder... do either or. Doing both won't break your web site... even if its not the problem ;)

I separated my html directories from my .cgi directories, and now everything is working great.

Now I have C:/Apache2/htdocs/(my html docs) and C:/Apache2/cgi-bin/(my cgi scripts) and they cross refer exaclty as they are supposed to.

Thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.