Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: CGI script connecting via terminal but not via browser

by aaron_baugher (Deacon)
on Sep 18, 2012 at 09:54 UTC ( #994248=note: print w/ replies, xml ) Need Help??


in reply to CGI script connecting via terminal but not via browser

Oops, never mind my original answer; I missed the line where you said the actual variables were filled in there.

It would seem there's a difference in the environment when it's run as a CGI by apache. You can compare by writing a simple CGI that reports on the environment and info on perl, like this:

#!/bin/sh perl -v echo ============================= set echo ============================= whoami echo ============================= pwd

Running that from the terminal and through a browser should help you spot any differences that might affect your script. The perl -v line especially will show if your script could be picking up different modules in either case.

Aaron B.
Available for small or large Perl jobs; see my home node.


Comment on Re: CGI script connecting via terminal but not via browser
Select or Download Code
Re^2: CGI script connecting via terminal but not via browser
by nkrgupta (Novice) on Sep 18, 2012 at 10:33 UTC

    Thanks Aaron. The Perl version is the same on both environments (5.8.8), however the PATH variable is significantly different:

    in CGI

    PATH == /sbin:/usr/sbin:/bin:/usr/bin

    in shell

    PATH == /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/eclipse/eclipse:/usr/local/apache-maven/apache-maven-2.2.1/bin:/usr/java/jdk1.6.0_34//bin

    Any of the paths missing in CGI could be causing this?

    Also, I have the following variable in shell, but not in CGI

    TOMCAT_HOME   ==   /usr/share/tomcat6/

      The PATH environment variable only affects which perl executable is used, if there happens to be more than one on the system. For instance, if you have /usr/local/bin/perl and /usr/bin/perl, the former will be picked up first by your shell, while the latter is used by your CGI. Two different perls, even if the same version, could have two different sets of modules and configurations. You could add which perl to my test CGI to report the full pathname of perl, and the results of perl -v will also show any differences in configs and the paths that perl checks for modules. If those match, then PATH doesn't matter beyond that.

      Aaron B.
      Available for small or large Perl jobs; see my home node.

        Yes, the same perl interpreter is being used in both places. Might then be a security restriction as suggested by moritz above.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-08-01 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (6 votes), past polls