Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

cgi works locally, but not on web server

by talk2kvj (Novice)
on Jun 16, 2004 at 22:09 UTC ( [id://367454]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks, I already posted this, but some suggested me to add as much code as possible. Here is my problem. I have the decisions.cgi script thast when run locally, prints out the expected output( prints the keys for the db file). but when run on the web server it doesnt show the keys in the FORM. so this basically creates a table and dropdown menu. this menu contains the 'keys'for the db file(the hash is %DECISIONS). The same script works on another server apache1.3x, db1.8x, perl5 without any problem. but on my server (apache2.x extranet, perl 5.8, db4. it doesnt work. here is the code and part of the output.I think I can shorten this a lot, but one of the monks advised me to put down the entire code.
print "<hr>"; print "<table border=1>"; #type is an array that has 4 elememts new1,new2,new3,new4. foreach ($cgx=0; $cgx <= $#type; $cgx++) { $typedb=$type[$cgx] . "db"; print "typedb $typedb\n"; tie %DECISIONS, 'DB_File', "$fdbl[2]clotdes$typedb"; #the fdbl is a flatfile that has different paths to different db files +. in this instance, it gives /var/www/cgibin/local/clotdes(new1/new2/ +new3/new4)db print "<td>\n"; print "$type[$cgx] info\n"; print "<FORM NAME=\"seeinfo\" action=\"../../../../cgi-bin/decisions.c +gi\" method=\"POST\">\n"; print "<select NAME=\"clone\">\n"; foreach $ckey (sort keys %DECISIONS) { print "<option>$ckey\n"; } print "</select>\n"; print "<input type=\"hidden\" name=\"seeclone\" value=\"$type[$cgx]\" +size=7><p>"; print "Filter<input type=\"radio\" name=\"simplify\" value=\"1\">"; print "<input type=\"submit\" value=\"View Info\">\n"; print "</form>\n"; $z++; if ($z == 4) { print "</td></tr><tr>\n"; }else{ print "</td>\n"; } untie %DECISIONS; }
OUTPUT
<hr><table border=1>typedb newdb <td> new info <FORM NAME="seeinfo" action="../../../../cgi-bin/decisions.cgi" method +="POST"> <select NAME="clone"> <option>b01 <option>b02 <option>b03 </select> <input type="hidden" name="seeinfo" value="pa" size=7><p>Filter<input +type="radio" name="simplify" value="1"><input type="submit" value="Vi +ew Info"> </form> </td>
the <option>b01 etc is the stuff that doesn't show up on webpage. and see in the first line of output, it parsed the flatfile containing paths and extracted the 'new' and concatenated it with db and printed it. but this is simply a flat{not db) file. There is no problem with the file permissions. Only stuff not replated to 'db' files is output on the webpage. the others like 'key' of the db hash doesnt showup. Is there any version conflict etcc.. if so, why would it run locally and open the db file . thanks in advance UPDATE :: Hi monks thanx for your suggestions. I tried everything that you all told me to do. and now it works. yeah the problem was the webserver was changerooted. anyway, to this extent it works. the entire script has around 1700 loc. the server is dyin when i run that script. I shall work on that. thank you all once again

Replies are listed 'Best First'.
Re: cgi works locally, but not on web server
by eXile (Priest) on Jun 17, 2004 at 00:30 UTC

    some thoughts:

    • Is your webserver changerooted? In that case the file might nog te accesible from the chrooted environment
    • Have you tried a minimal script to check if the script when run in cgi-mode can actually open the file? Replace the 'tie' line with something like:
      open "$fdbl[2]clotdes$typedb" or warn "cant open file\n";
      and you'll know.

Absoulte Paths
by chanio (Priest) on Jun 17, 2004 at 02:36 UTC
    You should try by using absoulte paths, first.

    Try indenting your code, simplifying it's display, so that you could easily update it by changing what is required at first glimpse...

    Is it possible to have your cgi-bin so deep inside your htdocs?

    Try absolute paths with a simple script. Then change your absolute paths with those relative ones, in the same simple script and see if it works again...

    .{\('v')/}
    _`(___)' __________________________
Re: cgi works locally, but not on web server
by bibo (Pilgrim) on Jun 17, 2004 at 03:30 UTC
    I see by this being your third post that you really really really want this to work. OK, I applaud your tenacity.

    First, I don't see a complete HTML document here, no headers, etc. Did you edit that out, or are you really using perl to print just the form and not the whole html?

    Have you tried just a "hello.cgi" thing to make sure that Apache2 is running the script at all? (although your output would indicate it is doing so)

    Next, can your "hello.cgi" script just open and print a line from a textfile in the same subdir as your db files? This would tell us if somehow Apache2 is preventing you from accessing the files there.

    Here is an example, adjust as needed and put in your same CGI subdir:

    #!/usr/bin/perl use strict; # fix this filename to match a small file in your db dir my $filename = "/var/www/cgibin/local/clotdesnew1db/file.txt"; # print "Content-type: text/plain\n\n"; print "Hello world\n"; print "filename is $filename\n"; # after first test completes, uncomment the next 5 lines #my @junk; #open(JUNK, $filename)|| die "Cannot open file $filename!"; #@junk = <JUNK>; #close(JUNK); #print "Line 1: $junk[0] \n";
    When I ran it here, I got output like this:
    Hello world filename is /var/www/cgi-bin/test1.txt Line 1: Dear brother:
    Let us know if this works or not, or what your tests tell you...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-03-29 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found