Install OCI8 on PHP 8.3+

With PHP 8.3, OCI is no longer compiled into the base package. Instead, you need to add it in using PECL or manually.

Here is how you do so manually.

The Steps here were performed on an Mac running Sequoia with the Oracle Instant Client installed under "/Users/oracle/product/19000/client_1". They should be mostly identical if you compile on Linux.

  1. Install Apache + PHP 8.3+ (this step should be obvious)
  2. Download OCI8 from https://github.com/php/pecl-database-oci8/archive/refs/tags/v3.4.tar.gz
  3. Copy the tgz into a work directory and extract
  4. cd pecl-database-oci8-3.4
  5. run "phpize" (make sure you run this from the php installation you want to install this extension into. You should see something like this:
  • Johns-MacBook-Pro:pecl-database-oci8-3.4 jchung$ phpize
  • Configuring for:
  • PHP Version:             8.4
  • PHP Api Version:         20240924
  • Zend Module Api No:      20240924
  • Zend Extension Api No:   420240924
  •  
  1. run "./configure"
  • Johns-MacBook-Pro:pecl-database-oci8-3.4 jchung$ ./configure
  • checking for grep that handles long lines and -e... /usr/bin/grep
  • checking for egrep... /usr/bin/grep -E
  • checking for a sed that does not truncate output... /usr/bin/sed
  • checking build system type... x86_64-apple-darwin24.6.0
  • checking host system type... x86_64-apple-darwin24.6.0
  • checking target system type... x86_64-apple-darwin24.6.0
  • checking for gawk... no
  • checking for nawk... no
  • checking for awk... awk
  • checking if awk is broken... no
  •  
  1. Make sure to set the variables CFLAGS and LDFLAGS to the location of the Oracle header files and libraries, respectively.
  • Johns-MacBook-Pro:pecl-database-oci8-3.4 jchung$ echo $LDFLAGS
  • -L/usr/local/gcc11/lib -L/Users/oracle/product/19000/client_1/lib
  • Johns-MacBook-Pro:pecl-database-oci8-3.4 jchung$ echo $CFLAGS
  • -I/usr/local/gcc11/lib/gcc/x86_64-apple-darwin18.7.0/11.3.0/include
  • Johns-MacBook-Pro:pecl-database-oci8-3.4 jchung$ 

 

  1. make 
  2. make install

 cc -I. -I/Users/jchung/apps/pecl-database-oci8-3.4 -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -I/Users/oracle/product/19000/client_1/sdk/include -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /Users/jchung/apps/pecl-database-oci8-3.4/oci8_failover.c -MMD -MF oci8_failover.dep -MT oci8_failover.lo  -fno-common -DPIC -o .libs/oci8_failover.o
/bin/sh /Users/jchung/apps/pecl-database-oci8-3.4/libtool --tag=CC --mode=link cc -shared -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -I/Users/oracle/product/19000/client_1/sdk/include -D_GNU_SOURCE  -L/Users/oracle/product/19000/client_1/lib  -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /Users/jchung/apps/pecl-database-oci8-3.4/modules  oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo oci8_failover.lo -Wl,-rpath,/Users/oracle/product/19000/client_1/lib -L/Users/oracle/product/19000/client_1/lib -lclntsh
cc ${wl}-flat_namespace ${wl}-undefined ${wl}suppress -o .libs/oci8.so -bundle  .libs/oci8.o .libs/oci8_lob.o .libs/oci8_statement.o .libs/oci8_collection.o .libs/oci8_interface.o .libs/oci8_failover.o  -L/Users/oracle/product/19000/client_1/lib -lclntsh  -Wl,-rpath -Wl,/Users/oracle/product/19000/client_1/lib
ld: warning: -undefined suppress is deprecated
dsymutil .libs/oci8.so || :
warning: no debug symbols in executable (-arch x86_64)
creating oci8.la
(cd .libs && rm -f oci8.la && ln -s ../oci8.la oci8.la)
/bin/sh /Users/jchung/apps/pecl-database-oci8-3.4/libtool --tag=CC --mode=install cp ./oci8.la /Users/jchung/apps/pecl-database-oci8-3.4/modules
cp ./.libs/oci8.so /Users/jchung/apps/pecl-database-oci8-3.4/modules/oci8.so
cp ./.libs/oci8.lai /Users/jchung/apps/pecl-database-oci8-3.4/modules/oci8.la
----------------------------------------------------------------------
Libraries have been installed in:
   /Users/jchung/apps/pecl-database-oci8-3.4/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Johns-MacBook-Pro:pecl-database-oci8-3.4 jchung$ su 
Password:
sh-3.2# make install
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-zts-20240924/
sh-3.2# /usr/local/apache2/bin/apachectl stop
sh-3.2# /usr/local/apache2/bin/apachectl start

  1. Run phpinfo(); to verify that the extension is installed.
  2. On Linux systems this installed w/o problem. It didn't show up until I manually added the following into php.ini 

    extension="/usr/local/lib/php/extensions/no-debug-zts-20240924/oci8.so"