Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Problem with cgi script

by nagalenoj (Friar)
on Feb 14, 2009 at 10:28 UTC ( #743791=perlquestion: print w/ replies, xml ) Need Help??
nagalenoj has asked for the wisdom of the Perl Monks concerning the following question:

Dear friends,

Thank you for your very useful tutorials on CGI for my last node Where can I read perl CGI?

I have tried my first cgi program. The problem is that nothing gets displayed in browser. I am using firefox 2.0.

use CGI; my $cgi = CGI->new; print $cgi->header(), $cgi->start_html(), $cgi->p("Hello World"), $cgi->end_html();

First, I executed the code in command line. It prints the expected output. Then, I tried perl -c to check the syntax, it said ok. But, when I tried in browser, nothing gets printed.

I have the file in cgi-bin directory, which is configured. I have given the permission as 777 for the file.

Help me to proceed..

Comment on Problem with cgi script
Download Code
Re: Problem with cgi script
by Corion (Pope) on Feb 14, 2009 at 10:32 UTC

    The first thing is to check in your web server error log. The webserver tells you what happens.

    Also, you're not printing the HTML elements. Start with an even simpler script:

    use strict; use CGI; my $cgi = CGI->new; print $cgi->header; print '<html><body>Hello World</body></html>';

    Then, modify that script to print out the HTML generated by CGI:

    ... print $cgi->header(); print $cgi->start_html(); print $cgi->p("Hello World"); print $cgi->end_html();
      That simple script is also not working in the browser.
        Well - what does the webserver error log say? Knowing the error message is the first step in solving the problem.
Re: Problem with cgi script
by Anonymous Monk on Feb 14, 2009 at 10:43 UTC
Re: Problem with cgi script
by ww (Bishop) on Feb 14, 2009 at 11:37 UTC
    This might be a longshot but are you sure your cgi-bin is in a permitted "place" and that the path you specify (in, presumptively, something.html) actually points to your script? (Some server/configurations take care of this for you by allowing that any call to <c>cgi-bin/script.cgi<c> get directed to a particular directory.)

    Customarily, cgi-bin is a sub-dir of your root. However, Apache can be configured to require or allow that it be elsewhere -- for example:

    /
       /cgi-bin
       /html
            /sub-dir1
            /sub-dir2
            index.html
            foo.html
            ...
    
    or
    /
        /html
            /cgi-bin
            /sub-dir1
            /sub-dir2
            index.html
            ...
    

    Depending on your server and its configuration, your script may ( have to be named script.cgi | allowed to named script.cgi or script.pl ) or some variant of those possibilities.

    Those variants include something like this:

    /
        /cgi-bin
        /html
            /cgi-bin
            /sub-dir1
            /sub-dir2
            index.html
            ...
    
    which can be confusing.
Re: Problem with cgi script
by jethro (Monsignor) on Feb 14, 2009 at 13:08 UTC

    Check the logfiles of your apache webserver, they normally are in /var/log/apache2/. Also firefox can show you the source text of the page it shows (right klick on the page to get a menu). Do you see a correct html page there?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-12-25 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (162 votes), past polls