Install NGINX + PHP + OCI8 + PDO_OCI on Mac OSX

2018/6/1 posted in  Database Bash

1. Download

Download Instant Client

https://gist.github.com/alexbonhomme/0d5976f2126bcde34b817e0143be0dff

  • instantclient-basic
  • instantclient-sqlplus
  • instantclient-sdk

Download PHP Source

  • php-x.y.z.tar.xz

Unzip all packages under ~/opt/ then get ~/opt/instantclient_V_R/ and ~/opt/php-x.y.z

2. Install OCI

. ~/src/bash/bash_profile.d/ora12c.sh

ln -s ~/opt/instantclient_V_R/sdk/include/*.h /usr/local/include/
ln -s ~/opt/instantclient_V_R/sqlplus /usr/local/bin/
ln -s ~/opt/instantclient_V_R/*.dylib /usr/local/lib/
ln -s ~/opt/instantclient_V_R/*.dylib.V.1 /usr/local/lib/
ln -s /usr/local/lib/libocci.dylib.V.1 /usr/local/lib/libocci.dylib
ln -s /usr/local/lib/libclntsh.dylib.V.1 /usr/local/lib/libclntsh.dylib
pecl install oci8

If the script prompt you to provide the path to ORACLE_HOME directory, respond with:
instantclient,/usr/local/lib

Bash Profile: ~/src/bash/bash_profile.d/ora12c.sh

# Oracle Instant CLient 12c
export ORACLE_HOME=${HOME}/opt/instantclient_12_2
export TNS_ADMIN=${ORACLE_HOME}/network/admin
export LD_LIBRARY_PATH=${ORACLE_HOME}:${LD_LIBRARY_PATH}
export PATH=${PATH}:${ORACLE_HOME}

TNS Config: ${TNS_ADMIN}/tnsnames.ora

DBT1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = a.b.c.d)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dbt1)
    )
  )
sqlplus USERNAME/PASSWORD@DBT1

3. Install PDO_OCI (by PECL)

cd ~/opt/php-7.2.5/ext/pdo_oci
phpize
./configure --with-pdo-oci=instantclient,/usr/local/lib,12.2
ls /usr/local/lib/php/pecl/20170718/

4. Config PHP Extensions

/usr/local/etc/php/7.2/conf.d/ext-oci8.ini

extension=oci8.so
extension=pdo_oci.so

5. Restart PHP Service

brew services restart php