简体   繁体   中英

Connecting to Oracle 11gR2 XE on Ubuntu 13 server via PHP

I am trying to connect to Oracle 11gR2 Xe on Ubuntu 13 server from another computer in the network, via PHP. I am using installs and examples followed from oci_connect like here:

<?php
query_cities();
function query_cities() {
if {
$c = oci_connect("hr", "hr", "localhost:1521/XE");
;
} else {
echo "No connection"; } 
?>

or another example like:

$c = oci_connect("hr", "hr", "192.168.1.33:1521/XE");

I have already enabled the remote connection in DB via SqlPlus

SQL> EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);

and i have unlocked the user HR

SQL> ALTER USER hr ACCOUNT UNLOCK;

but I can only find some connection via IPv6 on the network from SQL Developer, like netstat:

tcp6 0 0 192.168.1.33:1521 192.168.1.2:57563 ESTABLISHED 14843/oracleXE

tcp6 0 0 192.168.1.33:1521 192.168.1.2:59314 ESTABLISHED 15665/oracleXE

not from my browser and they are not on tcp IPv4. The browser window remain white .. no reaction, unresponsive and no error message. Should this be due to the TNSLR IP is active only on IPv6 or non of the oci_connect formulas are good enough or I am missing some other else?

I would appreciate any help on this issues

Alright, on the basis of received advice to seek the error in logs, I've found the message "*There is something wrong with your system - please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories*" and I decided to go through the sophisticated process of installing the Oracle InstantClient and reinstall OCI8 package, after the model from st-curriculum.oracle - with very small modifications, as follows:

  1. Oracle 11g R2 XE database and Apache2 / PHP server have been apriori installed on Ubuntu 13.10 server and system prepared (with prereqiuzite, swap file, kernel parameters, memory leak error recover, libraries and chkconfig emulator), as described in many posts.

  2. I stopped apache2 server

      service apache2 stop 

    and started DRCP connection pooling as in st-curriculum.oracle.com

  3. I created a user named PHPHOL (and alternate install Oracle's sample HR schema, if not already done at oracle install)

  4. Next I downloaded the Basic and the SDK Instant Client packages from OTN: oracle.com/technetwork/database/features/instant-client/index-100365.html and unzipped the packages in $ORACLE_HOME, (/u01/app/oracle/product/11.2.0/xe)

  5. Then I downloaded the OCI8 packeage from pecl.php.net/package/oci8 and installed in /opt/oci8 as instantclient

     phpise ./configure --with-oci8=instantclient,/u01/app/oracle/product/11.2.0/xe/instantclient_11_2 make / make install 
  6. I set the oracle environment path as in oracle technote

     export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/instantclient_11_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH=/opt/oci8/modules nano /etc/ld.so.conf.d/oracle.conf 

    and insert: /u01/app/oracle/product/11.2.0/xe/instantclient_11_2

     nano /etc/ld.so.conf.d/oci8.conf 

    and insert: /opt/oci8/modules

     nano /etc/ld.so.conf.d/shared.conf 

    and insert the installed shared extensions location: /usr/lib/php5/20121212

     ldconfig 
  7. Next I edited the configuration file php.ini to add: extension=oci8.so, set the date.timezone directive and added also the OCI8 1.4 extension class: oci8.connection_class = MYPHPAPP (for the st-curriculum.oracle.com examples, see link above)

  8. I made the link: $ORACLE_HOME/instantclient_11_2/libclntsh.so.11.1. to points to $ORACLE_HOME/instantclient_11_2/libclntsh.so

  9. Restart Oracle database and Apache services on Ubuntu 13.10 server

     /etc/init.d/oracle-xe force-reload service apache2 start 
  10. I verified in phpinfo() the oci8 was enabled, and I made the connect.php file like:

     $conn = oci_connect("hr", "hr", "localhost/xe"); 

or like the one from st-curriculum.oracle.com example.

From another computer on the same network I connected through a browser to oracle database on Ubuntu server and I've got

Connected to Oracle!

I hope this help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM