Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yajra/e993c781237c33d7eeeaf3efed76e4ce to your computer and use it in GitHub Desktop.
Save yajra/e993c781237c33d7eeeaf3efed76e4ce to your computer and use it in GitHub Desktop.
How to install OCI8 on macOS 10.15 (Catalina) with PHP 7.3 or 7.4 (Homebrew)

How to install OCI8 on macOS 10.15 (Catalina) with PHP 7.3 or 7.4

Requirements

  • Homebrew
  • Command Line Tools for Xcode
  • PHP 7.3 or 7.4 via Homebrew

Preparation

Create a folder to store Oracle Instant Client files.

sudo mkdir /opt/oracle

Download Oracle Instant Client

Download the following files from Oracle website

Unzip all theses files into a the directory /opt/oracle/instantclient_19_8.

Create symlinks

ln -s /opt/oracle/instantclient_19_8/sdk/include/*.h /usr/local/include/
ln -s /opt/oracle/instantclient_19_8/*.dylib /usr/local/lib/
ln -s /opt/oracle/instantclient_19_8/*.dylib.19.1 /usr/local/lib/
ln -s /usr/local/lib/libclntsh.dylib.19.1 /usr/local/lib/libclntsh.dylib

Install extension with PECL

pecl install oci8-2.2.0

If the script prompt you to provide the path to ORACLE_HOME directory, respond with:

instantclient,/opt/oracle/instantclient_19_8

Note:

If you ever got error command not found: pecl, make sure PHP bin folder is included in your environment path.

Test it out

Create a file containing the following codes.

if (function_exists('oci_connect')) {
    echo 'OCI8 is working!';
}
else {
    echo 'Whoopss...not working!';
}

Restart your HTTP Server and test.

References

@nyeyint
Copy link

nyeyint commented Aug 6, 2023

Hi @yajra, I tried many ways to use your package laravel/oci8 and getting stuck on oci8 extension on my Mac M1. Could you advise me on any resource, link please. I'm always stuck with below error message:

Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /opt/homebrew/lib/php/pecl/20190902/oci8.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/oci8.so, 0x0009): symbol not found in flat namespace '_OCIAttrGet'), /opt/homebrew/lib/php/pecl/20190902/oci8.so.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/oci8.so.so, 0x0009): tried: '/opt/homebrew/lib/php/pecl/20190902/oci8.so.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/php/pecl/20190902/oci8.so.so' (no such file), '/opt/homebrew/lib/php/pecl/20190902/oci8.so.so' (no such file))) in Unknown on line 0 PHP 7.4.33 (cli) (built: Aug 4 2023 14:45:21) ( NTS )

Thank You.

@yajra
Copy link
Author

yajra commented Aug 8, 2023

Make sure you are using the brew intel version if your device is M1/M2. Below are some references I used on my M2 setup.

Valet Setup

https://dev.to/ibrarturi/mac-m1-setup-for-local-development-with-laravel-valet-2lmk
https://earthly.dev/blog/homebrew-on-m1/

Docker Setup for OracleXE / Colima

https://github.com/abiosoft/colima#installation

Additional Scripts

The custom scripts I personally used to toggle intel/apple brew. Add this to the bash / zsh profile

arm() {
  arch -x86_64 $@
}

# Switch to Intel Brew
intel-brew() {
  eval "$(/usr/local/bin/brew shellenv)"
}

# Switch to Apple Brew
apple-brew() {
  export PATH=$PATH:/opt/homebrew/bin
  eval "$(/opt/homebrew/bin/brew shellenv)"
}

@nyeyint
Copy link

nyeyint commented Aug 8, 2023

Hi @yajra ,

Thank you so much for sharing your valuable knowledge and prompt respond.
I'm going try as your sharing.

Have a great ahead. 😍

@akhiidwandhare
Copy link

@yajra

I followed all steps but getting error something like this.
Any idea about it?

Screenshot 2023-12-14 at 17 18 46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment