Your script, the OS, and the edition of Oracle would be useful information to share.
Check "Commonly Seen Connection and Environment Errors" on page 107 of http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html
There are various things that could be the cause e.g. perhaps the section "Check Apache Has Oracle File Access" is relevant.
There was a changePerm.sh script in a later 10.2 patchset to help set permissions. Oracle 10g Express Edition and Oracle 11g didn't have the same restrictive settings, so generally just the home directory needed extra access granted in these other releases.
If you're uncomfortable (for whatever reasons) with granting the extra access, you could use PHP with the free Oracle Instant Client libraries.
On this same machine i installed perl-DBI and Oracle-DBD.
i can run a perl script (which connects to a ORACLE database) with command line and getting the output but when i run it through web it gives the following error.
[Mon Apr 08 11:10:49 2013] [error] [client 10.141.6.213] install_driver(Oracle) failed: Can't load '/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.10.1: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.
i can run php script through web which fetch data from a oracle database on this machine.
You probably need to set the various Oracle environment variables so the webserver has access to them.
There are some recent threads in this forum that might help you find how & where to set them for