Solved

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

Posted on 2008-10-06
14
1,164 Views
Last Modified: 2013-12-20
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
Comment
Question by:sh_
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Do you get an error message  through the browser?
Does the CGI user have the same privileges as the command line user?
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
Do you get any output in the browser at all?
0
 

Author Comment

by:sh_
Comment Utility
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
 
LVL 4

Assisted Solution

by:urgoll
urgoll earned 50 total points
Comment Utility
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
 

Author Comment

by:sh_
Comment Utility
I have installed apache as root and the web server is running as ROOT.
0
 
LVL 4

Expert Comment

by:urgoll
Comment Utility
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
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 50 total points
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:sh_
Comment Utility
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
 
LVL 4

Expert Comment

by:urgoll
Comment Utility
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
 

Author Comment

by:sh_
Comment Utility
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
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 50 total points
Comment Utility
> 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
 

Author Comment

by:sh_
Comment Utility
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
 

Accepted Solution

by:
sh_ earned 0 total points
Comment Utility
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
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility

[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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now