Solved

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

Posted on 2008-10-06
14
1,181 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 22655706
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
ID: 22655728
Do you get any output in the browser at all?
0
 

Author Comment

by:sh_
ID: 22655752
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 4

Assisted Solution

by:urgoll
urgoll earned 50 total points
ID: 22655871
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_
ID: 22655994
I have installed apache as root and the web server is running as ROOT.
0
 
LVL 4

Expert Comment

by:urgoll
ID: 22656118
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
ID: 22656416
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
 

Author Comment

by:sh_
ID: 22657620
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
ID: 22658899
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_
ID: 22660634
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
ID: 22664906
> 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_
ID: 22683271
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
ID: 22683477
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
ID: 22684804

[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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
clicking to find my folders on wamp 8 46
debug scriptblock parameters in powershell script 2 48
Google Chrome: Debugging AJAX call 6 38
construct a query sql 11 42
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

732 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