问题
I am using Centos 6 64 bit OS. Recently i have installed OCI8 extension with php. After making all configuration i tried to execute the function oci_connect to connect with a Oracle Database remotely.
Unfortunately i got this error:
Fatal error: Call to undefined function oci_connect() in /var/www/html/index.php on line 5
I have installed oci8 like this:
OCI8
Download the OCI8 source using pear
$ pear download pecl/oci8 $ tar -xvf oci8-1.4.9.tgz $ cd oci8-1.4.9
Build and install the extension.
$ phpize $ ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib $ make $ sudo make install
To enable the extension, add a file named oci8.ini in /etc/php.d with this content:
extension=oci8.so
Validate that it was successfully installed.
$ php -i | grep oci8
You should see something like this:
/etc/php.d/oci8.ini, oci8 oci8.connection_class => no value => no value oci8.default_prefetch => 100 => 100 oci8.events => Off => Off oci8.max_persistent => -1 => -1 oci8.old_oci_close_semantics => Off => Off oci8.persistent_timeout => -1 => -1 oci8.ping_interval => 60 => 60 oci8.privileged_connect => Off => Off oci8.statement_cache_size => 20 => 20
Ref: http://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/
I would like to mention that when the installation started is message was display something like: instantclient, /../../ to PUT THE PATH. I didn't give anything, just pressed enter. Is it the issue that i can't connect to Oracle ?
Need your help badly.
Thanks
回答1:
I have managed to solve problem. Actually the problem was the the environment library was not loaded. so i have loaded the environment of oracle manually via PHP .
Here is my code:
> if (!$conn):
> /// INCLUDING ORACLE_HOME MANUALLY
> putenv("ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1/");
> // INCLUDING LD_LIBRARY_PATH MANUALLY
> putenv("LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/dbhome_1/lib:/lib:/usr/lib:/lib:/usr/lib:/usr/local/lib");
>
> $conn = "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521)))
> (CONNECT_DATA = (SERVICE_NAME = data)))";
> $conn = oci_pconnect("username", "password", $conn);
> endif;
> if($conn):
> return $conn;
> endif;
> if(!$conn):
> redirect('login');
> endif;
> }
Hope that it will help everyone
Thanks,
回答2:
step-01 For correct installation oci8 refer this link
http://www.techinfobest.com/install-oci8/
After successfully installation
step-02 Check php configuration where separate section for OCI8 listed are not
<?php echo phpinfo(); ?>
if not listed.
step-03 check your httpd error log by terminal
cat /var/log/httpd/error_log
find any php error occured while after httpd service starting like
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/oci8.so' - libclntsh.so.12.1: cannot enable executable stack as shared object requires: Permission denied in Unknown on line 0
then it is the problem in your selinux permission. find below link to proper permission.
step-03 http://www.cdatazone.org/index.php?/archives/37-PHP,-Oracle-and-SELinux.html
I have followed these steps and got success to oracle installation
回答3:
For Centos 7, I do not know if works in Centos 6.
$ sudo vim /etc/ld.so.conf.d/oracle-instantclient.conf
// Add path to oracle client lib, the XX is the version, ex: /usr/lib/oracle/XX/client64/lib
$ sudo ldconfig
$ sudo service php-fpm restart
Done!
来源:https://stackoverflow.com/questions/23731201/centos-6-php-oci8-extention-is-not-working-undefined-function-oci-connect