This is an example of using the Oracle InstantClient 11g with PHP.
Installation InstantClient for PHP
This is based on work from the past – but I appeared to have done the following:
- Installed InstantClient and Pear to manage the php installation.
sudo yum install php-pear
sudo rpm -ivh oracle-instantclient11.1-basic-11.1.0.7.0-1.i386.rpm
sudo rpm -Uvh oracle-instantclient11.1-devel-11.1.0.7.0-1.i386.rpm
- Update the library cache to include oracle:
sudo vi /etc/ld.so.conf.d/oracle.conf
- This file just contains the line:
/usr/lib/oracle/11.1/client/lib
- Used pecl to install the OCI client into PHP:
sudo pecl install oci8
- Updated PHP to then make use of the installed module
sudo vi /etc/php.d/oci8.ini
- This file just contained
; Enable oci8 extension module
extension=oci8.so
- I then restarted the web server.
sudo /etc/init.d/httpd restart
Testing
You can then test this by creating a php file with the following content:
<?php $conn = oci_connect('[user]', '[password]', ' [//]host_name[:port][/service_name][:server_type][/instance_name]'); $query = 'select table_name from user_tables'; $stid = oci_parse($conn, $query); oci_execute($stid, OCI_DEFAULT); while ($row = oci_fetch_array($stid, OCI_ASSOC)) { foreach ($row as $item) { echo $item." "; } echo "<br>\n"; } oci_free_statement($stid); oci_close($conn); ?>
Then use a browser to get to this web page, and it should show you the content of user_tables.
Troubleshooting
Then, if SELinux its not turned off then the following is needed, (but we don’t want to do it this way as it’s painful and make SELinux a bit pointless):
sudo chcon -t textrel_shlib_t '/usr/lib/oracle/11.1/client/lib/libnnz11.so' sudo chcon -t textrel_shlib_t '/usr/lib/oracle/11.1/client/lib/libclntsh.so.11.1' sudo chcon -t textrel_shlib_t '/usr/lib/php/modules/oci8.so' sudo execstack -c /usr/lib/oracle/11.1/client/lib/libclntsh.so sudo execstack -c /usr/lib/oracle/11.1/client/lib/libclntsh.so.11.1 sudo execstack -c /usr/lib/oracle/11.1/client/lib/libnnz11.so sudo chcon -u system_u '/usr/lib/php/modules/oci8.so' sudo execstack -s /usr/sbin/httpd sudo /usr/sbin/setsebool -P httpd_can_network_connect 1