I'm trying to setup a CentOS 5.5/64 bit VM to access a remote Oracle database with PHP and Perl scripts. (I have no experience with Oracle, have only programmed and administrated some PostgreSQl and MySQL before.)
I've installed the following Oracle Instant Client rpms:
oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.2.0.x86_64.rpm
And have added the following variables to my .bash_profile:
export TNS_ADMIN=/etc
export ORACLE_HOME=/usr/lib/oracle/11.2
export LD_LIBRARY_PATH=$ORACLE_HOME/client64/lib
PATH=$PATH:$HOME/bin:/sbin:$ORACLE_HOME/client64/bin
Into the file /etc/tnsnames.ora
I've written the infos received from the colleague at the remote site running the Oracle database:
some_string =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = my_address)(PORT = my_port))
)
(CONNECT_DATA =
(SERVICE_NAME = PDTT)
)
)
The nice part is that I can connect from CLI now by running
sqlplus 'my_user/my_password@//my_address:my_port/PDTT'
and then can see some tables by issueing:
select table_name from user_tables;
And also I've run sudo pecl install oci8
successfully, added the file /etc/php.d/oci8.ini
containing:
extension=oci8.so
and can see the following phpinfo() output
Now my questions and problems please:
1) How should I setup ORACLE_SID variable and how to call sqlplus once it is set? Can/should I use ORACLE_SID from PHP and Perl scripts?
2) I run sudo -E perl -MCPAN -e shell
and it works well when installing other Perl modules, but for "install DBD::Oracle" it fails with:
CPAN.pm: Going to build T/TI/TIMB/DBD-Oracle-1.26.tar.gz
Using DBI 1.52 (for perl 5.008008 on x86_64-linux-thread-multi) installed in /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBI/
Configuring DBD::Oracle for perl 5.008008 on linux (x86_64-linux-thread-multi)
Remember to actually *READ* the README file! Especially if you have any problems.
The ORACLE_HOME environment variable value (/usr/lib/oracle/11.2) is not valid.
It must be set to hold the path to an Oracle installation directory
on this machine (or a machine with a compatible architecture).
For an Instant Client install, the directory should include an sdk subdirectory.
See the appropriate README file for your OS for more information.
ABORTED!
Running make test
Make had some problems, maybe interrupted? Won't test
Running make install
Make had some problems, maybe interrupted? Won't install
It mentions "sdk" dir above, but the rpm didn't have that dir at all:
# rpm -ql oracle-instantclient11.2-devel | grep -i sdk
#
Thank your for any hints and also any useful tips for Oracle installation and usage. There is lot of Oracle information out there, but it often assumes that Oracle is installed at the same machine.
I had the same problem. SOLVED adjusting de enviroment variable ORACLE_HOME, like this:
And inside $ORACLE_HOME I have respective subdirectories:
bin lib sdk
After that I could install DBD::Oracle just fine.
For question #1, to access a remote database, ORACLE_SID is irrelevant. ORACLE_SID is only useful when the client and server are running on the same host. Given your tnsnames.ora file, you should be able to connect to the remote database using:
you can also use
However, I generally shy away from supplying passwords on the command line - snoopy users and the ps command can sometimes give it away. Let the database prompt you for the password. In fact, I have just gotten into the habit of issuing the sqlplus command thusly:
and then at the prompt issue
and nobody sees even the user or database you connect to, and I never have to think about it.
As for question #2, can't help you out.
EDIT:
Well, maybe I can help out on #2. I found this link on using DBD with instant client. Apparently you have to download/install the sdk instant client too. See step 3 in the link.
1) If you want to leave off the @connect_string you can set the TWO_TASK environment variable to the name tnsnames alias (in this case some_string).
The same is accomplished using the LOCAL variable on windows.
2) Sounds like sudo is reseting your environment variables. You will need to add $ORACLE_HOME and perhaps others to the env_keep line in your sudoers file. Other changes to the sudoers file that will acconplish the same thing are discussed here.