Skip to content

Instantly share code, notes, and snippets.

@loziju
Created February 2, 2020 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loziju/89737ee75edd24293eb1de31a47dbb84 to your computer and use it in GitHub Desktop.
Save loziju/89737ee75edd24293eb1de31a47dbb84 to your computer and use it in GitHub Desktop.
# Installation
This procedure is tested on Mac OS X 10.14.6 with Developers tools installed (xCode).
PHP 5.6 installed with Homebrew.
## Preparation
Download the following files from [Oracle website](https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html) (yes, you need to create an account and accept terms):
* instantclient-sdk-macos.x64-19.3.0.0.0dbru.zip
* instantclient-basiclite-macos.x64-19.3.0.0.0dbru.zip
* instantclient-sqlplus-macos.x64-19.3.0.0.0dbru.zip
Create and unzip all theses files into a the directory `/usr/local/lib/instantclient/instantclient_19_3/`.
## Create symlinks
```
ln -s /usr/local/lib/instantclient/instantclient_19_3/sdk/include/*.h /usr/local/include/
ln -s /usr/local/lib/instantclient/instantclient_19_3/sqlplus /usr/local/bin/
ln -s /usr/local/lib/instantclient/instantclient_19_3/*.dylib* /usr/local/lib/
```
## Test with sqlplus instantclient
I recommand to install Oracle Server with a VirtualBox [VM preinstalled](https://www.oracle.com/database/technologies/databaseappdev-vm.html).
```
/usr/local/bin/sqlplus oracle/oracle@192.168.99.100:1521
```
(I can't get the above to work till authenticated, but as long as sqlplus works and tries to authenticate with the server, we're good)
## Install oci8 extension with pecl
```sh
sudo pecl install oci8-2.0.10 # phpv5.2 - phpv5.6
sudo pecl install oci8 # phpv7
```
If the script prompt you to provide the path to ORACLE_HOME directory, respond with:
```
shared,instantclient,/usr/local/lib
```
> Note: If you got PECL error:
```sh
touch $(brew --prefix php52)/lib/php/.lock && chmod 0644 $(brew --prefix php52)/lib/php/.lock # phpv5.2
touch $(brew --prefix php56)/lib/php/.lock && chmod 0644 $(brew --prefix php56)/lib/php/.lock # phpv5.6
touch $(brew --prefix php70)/lib/php/.lock && chmod 0644 $(brew --prefix php70)/lib/php/.lock # phpv7
```
And your are done, normally pecl will automatically load the extension in your `php.ini`. If not, add the following line to your `php.ini`:
```
extension=oci8.so
```
Restart your HTTP Server and test.
## Compile oci8 extension
If the above still doesn't work, compile your own oci8.so:
[original article](http://www.baldwhiteguy.co.nz/technical/index_files/mac-osx-oci8-oracle-php.html)
1. Ensure you have autoconf:
```sh
brew install autoconf
```
2. Get and untar http://pecl.php.net/package/oci8/2.0.12
3. Go to the folder
4. Run the following:
```sh
phpize
./configure --with-oci8=shared,instantclient,/usr/local/lib
make
sudo make install
```
Substitute `/usr/local/lib` with the path to your ORACLE_HOME (Instant client) directory as per the above.
Ensure that your php.ini is loading the exension.
Restart your HTTP Server and test.
## Install pdo_oci
To installing `pdo_oci`. You must do following command:
```
mkdir -p /usr/local/lib/oracle/11.2.0.4/client
ln -sf /usr/local/instantclient/11.2.0.4/sdk/include /usr/local/lib/oracle/11.2.0.4/client/
cd /tmp
pecl download pdo_oci
tar -xvf PDO_OCI-1.0.tgz
cd PDO_OCI-1.0
```
After that, download this patch and apply:
```
wget https://gist.githubusercontent.com/krisanalfa/e0beaa512b4677c51a7c/raw/214c36a65685c9c24102ad7b703d040a7fb60243/config.m4.patch
patch config.m4 < config.m4.patch
```
Also, we need to patch `pdo_oci.c` file:
```
wget https://gist.githubusercontent.com/krisanalfa/1bb09ad8f9147937bbeb/raw/b66ee62e8f4601a0f669e40a619881734787d4cd/pdo_oci.c.patch
patch pdo_oci.c < pdo_oci.c.patch
```
We should tell our configuration to use `11.2.0.4` version, so it will find the right version in our system.
```
phpize
./configure --with-pdo-oci=instantclient,/usr/local/lib,11.2.0.4
```
Build it and install it:
```
make
make install
```
After this open your `php.ini` and add this line:
```
extension=pdo_oci.so
```
Test it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment