I want to access an Oracle DB from my PHP scripts. On my Red Hat 8.8 server I ran
sudo yum install https://download.oracle.com/otn_software/linux/instantclient/oracle-instantclient-basic-linuxx64.rpm
to install the InstantClient.
I have added these two extensions to my php.ini
extension=pdo_oci
extension=oci8_19 ; Use with Oracle Database 19 Instant Client
but when I run my PHP script I get the error message
could not find driver
phpinfo() shows as loaded PDO drivers
mysql, pgsql, sqlite
What I am missing here?
The instantclient RPM does not include PHP modules, you have to compile those yourself. You also need the SDK.
Download the SDK and drop the sdk
folder into the same place where the instantclient lib
folder went:
wget https://download.oracle.com/otn_software/linux/instantclient/2380000/instantclient-sdk-linux.x64-23.8.0.25.04.zip
unzip instantclient-sdk-linux.x64-23.8.0.25.04.zip
mv instantclient_23_8/sdk /usr/lib/oracle/23/client64/lib
Install dev tools if you don't already have them:
yum install php-devel php-pear make
Download and compile the module. Note the version you need depends on what PHP version you're using. See here for details.
echo "instantclient,/usr/lib/oracle/23/client64/lib" | pecl install oci8-2.2.0
This should put oci8.so
in your PHP modules directory:
ls -l /usr/lib64/php/modules/oci8.so
-rw-r--r-- 1 root root 897744 Jun 5 13:54 oci8.so
Now you can add extension=oci8
to your ini
file and run php -m
to verify it loaded.
Note this gets you the oci8
module. If you want pdo_oci
you'll have to compile that separately. You surely don't need both.