Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Prompted to Open or Save CGI Program -- configuration issue?

by neutron (Sexton)
on Mar 17, 2009 at 03:02 UTC ( [id://751091]=perlquestion: print w/replies, xml ) Need Help??

neutron has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get an html page to run cgi script, using the form "GET" command. When I submit my form entry, I'm then prompted to either open, save or cancel the cgi script. I can run the script independently but not through the html page. Any ideas? Perhaps I have my Apache server set up in correctly. I should also note, I'm using apache 2.2.11 and both files are stored in the same file path (cgi-bin).

Here's the html:
<html><head><title>Test Form</title></head> <body> <form action="10_cgi.cgi" method="GET"> Enter some text here: <input type="text" name="sample_text" size=30> <input type="submit"> </form> </body></html>
Here's the cgi ("10_cgi.cgi"):
#!/perl/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; print header; print start_html( "Get Form" ); #my %form; #foreach my $p (param()) { # $form{$p} = param($p); # print "$p = $form{$p}<br>\n"; #} print end_html;

Replies are listed 'Best First'.
Re: Prompted to Open or Save CGI Program -- configuration issue?
by targetsmart (Curate) on Mar 17, 2009 at 06:16 UTC
    Debugging CGI programs
    When writing CGI programs, there are many problems which may affect their execution. Since these will not always be easily understood by examining the web browser output, there are other ways to determine whatÂ’s going wrong.

    If there seems to be a problem first try the following steps:
    1. Check that your program compiles by using perl -c
    2. Check the permissions on your cgi program. If it is not world executable then it won’t work.
    3. Run your program on the command line. If your program waits for input, that’s your opportunity to pass in parameters. For the moment, press CTRL-d.
    4. If your program runs fine on the command line but still does not output to the browser, make sure that you have not forgotten to print the header before any other output.
    5. Check the HTML source that you’re printing. Make sure that you’ve closed any tables you’ve opened and not made any obvious HTML errors.
    6. Check the web server’s log files. The location of these vary from system to system. On our system they’re in /var/log/apache/.

    the above text is from http://perltraining.com.au/courses/webdev.html

    my apache setting is like this in /etc/apache2/httpd.conf and my apache ( Server version: Apache/2.2.3) is able to run cgi scripts properly which is located in /var/www/cgi-bin/

    <VirtualHost *> ScriptAlias /cgi-bin/ /var/www/cgi-bin/ <Directory "/var/www/cgi-bin"> Options ExecCGI SetHandler cgi-script </Directory> </VirtualHost>
    I found Troubleshooting Perl CGI scripts also helpful.

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re: Prompted to Open or Save CGI Program -- configuration issue?
by Anonymous Monk on Mar 17, 2009 at 09:57 UTC
    When I submit my form entry, I'm then prompted to either open, save or cancel the cgi script.
    I'll bet if you choose to save, and then examine what gets saved, it will be the perl sourcecode to your program.
Re: Prompted to Open or Save CGI Program -- configuration issue?
by neutron (Sexton) on Mar 17, 2009 at 12:16 UTC
    Vivek, thanks for the great trouble shooting pointers. As for the apache server settings, I'm still struggling. Here's what the original looks like:
    <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi- +bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory>
    I also tried a number of modifications:
    <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi- +bin"> Options ExecCGI SetHandler cgi-script </Directory>
    Another:
    <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi- +bin"> AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch Includes ExecCGI </Directory>
    I also did a few more iterations of these, but no to no avail. I should also note that I think the conf files for the different apache versions are quite a bit differnt. For example my file doesn't have the <virtualhost *> command. Any ideas, would be much appreciated.
      <Directory "PATH FOR YOUR CGI SCRIPTS"> Options ExecCGI SetHandler cgi-script </Directory>

      is instructing apache to treat the files found at that particular directory as Perl scripts. So, write there the location of the scripts, and make sure they are executable.

      my file doesn't have the <virtualhost *> command
      Maybe your httpd.conf doesn't have the virtualhost directive but, if you look at the dir where your httpd.conf file is, you will find a few directories like vhosts, extra, or other ..... Peeking into the files in there you'll probably find that directive. There are different ways to configure vhosts, I suggest you read some introductory material on Apache.

      So are you CGI scripts in the /cgi-bin/ directory?
        Yes. Well at least in a subdirectory under cgi-bin. And they're both in same subdirectory.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://751091]
Approved by holli
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-16 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found