Oracle client extension under PHP of OCI8 installation tutorial

  • 2021-07-18 07:14:30
  • OfStack

Recent projects require php to access the oracle database and have to install oci8 extensions for php under linux. php can also use pdo to access the oracle database, but you still need to install the client.

First of all, download the relevant files from this page of oracle official website. Pay attention to the version of the database server. 1 must correspond, otherwise it will not be connected after successful installation. At the same time, it is necessary to distinguish 32-bit and 64-bit servers. For example, the database server I want to connect to is oracle 10.2. 0.4 and 64-bit host, so I want to download the following 3 files:


oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm
oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm
oracle-instantclient-sqlplus-10.2.0.4-1.x86_64.rpm

1. Install with the following command


# rpm -ivh oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm    oracle-instantclient-sqlplus-10.2.0.4-1.x86_64.rpm

2. Install the OCI8 PHP extension


# yum install libaio
# cd ~
# wget http://pecl.php.net/get/oci8-1.3.5.tgz

3. Then execute the command


# tar zxvf oci8-1.3.5.tgz
# cd oci8-1.3.5/
# /usr/local/php5/bin/phpize  CFLAGS=/usr/lib/oracle/11.2/client64/ CXXFLAGS=/usr/lib/oracle/11.2/client64/
# ./configure --with-php-config=/usr/local/php5/bin/php-config --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib/
# make
# make install( Run here a few more times , Until the following prompt appears )
 
[root@webserver02 oci8-1.3.5]# make install
/bin/sh /root/oci8-1.3.5/libtool --mode=install cp ./oci8.la /root/oci8-1.3.5/modules
cp ./.libs/oci8.so /root/oci8-1.3.5/modules/oci8.so
cp ./.libs/oci8.lai /root/oci8-1.3.5/modules/oci8.la
PATH="$PATH:/sbin" ldconfig -n /root/oci8-1.3.5/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/oci8-1.3.5/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 `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing shared extensions:     /usr/local/php5/lib/php/extensions/no-debug-zts-20090626/
# cd /usr/local/php5/lib

4. Create an ext directory


# mkdir ext/

Copy the oci8.so file to the ext directory of php. ini
# cp /root/oci8-1.3.5/modules/oci8.so /usr/local/php5/lib/ext/

5. Add extension=oci8.so to php. ini

As follows:


extension_dir = "/usr/local/php5/lib/ext"
extension = "oci8.so"
session.save_path = "/tmp/php"
oci8.privileged_connect = on

Restart the apache service:


/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start

Refresh the test page. If you find oci8, you are done.


Related articles: