[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1221
  • Last Modified:

When I run the script from the command line, it works but not on the browser

When I execute the Perl/CGI script on the command line, it works but not through the browser. I am using Apache webserver installed as root in Linux.

OS :  => SUSE Linux 10.2
Perl :  => v5.8.8 built for i586-linux-thread-multi
Oracle :  => 10.2.0.1
DBI :  => 1.607
DBD::Oracle => 1.22
Apache ::  => Server version: Apache/2.2.9 (Unix)

Uname -a

Linux mac-linux 2.6.16.60-0.23-default #1 Thu May 15 06:38:31 UTC 2008 i686 i686 i386 GNU/Linux



#!/usr/bin/perl -w
 
use strict;
use lib qw(/usr/lib/perl5/site_perl/5.8.8);
BEGIN {
$ENV{ORACLE_HOME} = "/dbs/oracle/product/10.2.0.1";
$ENV{LD_LIBRARY_PATH} = "/dbs/oracle/product/10.2.0.1/lib:/usr/local/lib";
$ENV{TNS_ADMIN} = "/dbs/oracle/product/10.2.0.1/network/admin";
$ENV{ORA_NLS} = "/dbs/oracle/product/10.2.0.1/nls/data";
$ENV{NLS_LANG} = "AMERICAN_AMERICA.US7ASCII";
$ENV{ORA_NLS10} = "/dbs/oracle/product/10.2.0.1/nls/data";
$ENV{PATH} = "/dbs/oracle/product/10.2.0.1/bin:/usr/bin";
}
 
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBI; # we.ll talk about this in more detail later
use DBD::Oracle;
 
my $url = url;
print header,
start_html;
DBI->trace(1, '/tmp/11.log');
my $db = DBI->connect( 'dbi:Oracle:ORCL10G', 'scott', 'tiger' ) || die( $DBI::errstr . "\n" );
$db->{AutoCommit}    = 0;
$db->{RaiseError}    = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize}  = 16;
my $SEL = "select * from emp";
my $sth = $db->prepare($SEL);
$sth->execute();
 
while ( my @row = $sth->fetchrow_array() ) {
    foreach (@row) {
        $_ = "\t" if !defined($_);
        print "$_\t";
    }
    print "\n";
}
 
END {
    $db->disconnect if defined($db);
}
print end_html;

Open in new window

Apache-err.txt
0
sh_
Asked:
sh_
  • 6
  • 3
  • 2
  • +2
4 Solutions
 
ozoCommented:
Do you get an error message  through the browser?
Does the CGI user have the same privileges as the command line user?
0
 
TintinCommented:
Do you get any output in the browser at all?
0
 
sh_Author Commented:
This is what I get in the browser.
=======================================

Software error:

ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.

For help, please send mail to the webmaster (you@example.com), giving this error message and the time and date of the error.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
urgollCommented:
Usually, the web server runs under an unprivileged user such as the 'apache' user. Look at the 'User' statement in the httpd.conf file in your apache config directory.

Assuming it is indeed the apache user, try this as root:
# su - apache
$ /usr/local/apache2/cgi-bin/db.cgi

This will change your identity to the apache user and run the CGI. If you get any errors, check the file permissions on the Oracle install path so confirm that all users are able to connect.

Regards,
Christophe
0
 
sh_Author Commented:
I have installed apache as root and the web server is running as ROOT.
0
 
urgollCommented:
Try this: remove the BEGIN{ } around the definition of your env variable, and move those to line 19 (after the use DBD::Oracle statement), and see if it makes a difference.

According to the DBD::Oracle manual page, the error you are seeing (ERROR OCIEnvNlsCreate) happens when ORACLE_HOME is not defined or is invalid.
0
 
TintinCommented:
Running Apache as root is an *extremely* dangerous thing to do.  Why did you do it that way?  I sincerely hope this isn't an Internet facing server.
0
 
sh_Author Commented:
I have tried removing the BEGIN{} and also the blank line at 19. Still am hitting the same error. This is a test machine and not connected to internet, hence running it as ROOT. I really dont know what I am missing. All the installations are perfect..
0
 
urgollCommented:
You can also try to move the environment definition to the apache web server. In your httpd.conf, add the following snippet and restart the web server.

Alternatively, do you have anything of interest in the DBI trace defined at line 23 ?

Regards,
Christophe
SetEnv ORACLE_HOME "/dbs/oracle/product/10.2.0.1"
SetEnv LD_LIBRARY_PATH "/dbs/oracle/product/10.2.0.1/lib:/usr/local/lib"
SetEnv TNS_ADMIN "/dbs/oracle/product/10.2.0.1/network/admin"
SetEnv ORA_NLS "/dbs/oracle/product/10.2.0.1/nls/data"
SetEnv NLS_LANG "AMERICAN_AMERICA.US7ASCII"
SetEnv ORA_NLS10  "/dbs/oracle/product/10.2.0.1/nls/data"
SetEnv PATH  "/dbs/oracle/product/10.2.0.1/bin:/usr/bin"

Open in new window

0
 
sh_Author Commented:
Hi,

Adding the variables to httpd.conf file didnt help. I am landing in the same page with errors.
The DB tracefile is empty when I try to call the db.cgi script through the browser.

Regards,
Sh
0
 
ahoffmannCommented:
> When I execute the Perl/CGI script on the command line,

did you do that as root (as the web server runs as root)?
If so, check is your environment contains the proper ORACLE* variables. You need to add these variables to you perl scrip using  $ENV{}
0
 
sh_Author Commented:
Have tried the above solution and it has not worked. Can somebody help to check the below trace and advise me..Appreciate the help in advance.

======================== TRACE  ===============================

[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     DBI 1.607-ithread default trace level set to 0x0/1 (pid 1975) at db.cgi line 19
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     -> DBI->connect(dbi:Oracle:ORCL10G, scott, ****)
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     -> DBI->install_driver(Oracle) for linux perl=5.008008 pid=1975 ruid=2 euid=2
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]        install_driver: DBD::Oracle version 1.22 loaded from /usr/lib/perl5/site_perl/5.8.8/i586-linux-thread-multi/DBD/Oracle.pm
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     <- STORE
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] ('ShowErrorStatement'
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] , 1
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] )
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] =
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  1
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  at Oracle.pm line 68
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     <- install_driver= DBI::dr=HASH(0x840cae0)
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     !! ERROR: '-1' 'ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.' (err#0)
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     <- connect
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] ('ORCL10G'
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] , 'scott'
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] , ...)
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] =
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  undef
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  at DBI.pm line 638
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     <- $DBI::errstr= 'ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.'
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]        DBI connect('ORCL10G','scott',...) failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] [Mon Oct  6 20:37:30 2008] db.cgi: DBI connect('ORCL10G','scott',...) failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc. at /usr/local/apache2/cgi-bin/db.cgi line 20
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     <- $DBI::errstr= 'ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.'
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] [Mon Oct  6 20:37:30 2008] db.cgi: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     !! ERROR: '-1' CLEARED by call to disconnect_all method
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     <- disconnect_all
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] =
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  (not implemented)
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  at DBI.pm line 717
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] !   <- DESTROY
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] (DBI::dr=HASH(840cae0)
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] )
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1] =
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  undef
[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]  during global destruction
0
 
sh_Author Commented:
I shall close this question.

The solution i had implemented was to install apache as oracle user and start the webserver. I am sure this is not acceptable, but atelast a work around for me to proceed further with my testings.

Thanks to all, for your help and knowledge.
0
 
ahoffmannCommented:

[Mon Oct 06 20:37:30 2008] [error] [client 192.168.1.1]     !! ERROR: '-1' 'ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.' (err#0)


the solution -you asked for- is as I already suggested in http:#22664906
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now