Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save syahzul/2632262df21974ecd02be3ccce66fbef to your computer and use it in GitHub Desktop.
Save syahzul/2632262df21974ecd02be3ccce66fbef 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

@anandabayu
Copy link

Hi can you help me, I got error

pecl/oci8 requires PHP (version >= 8.0.0), installed version is 7.4.16
No valid packages found
install failed

@syahzul
Copy link
Author

syahzul commented Apr 12, 2021

Hi can you help me, I got error

pecl/oci8 requires PHP (version >= 8.0.0), installed version is 7.4.16
No valid packages found
install failed

try running this command:

pecl install oci8-2.2.0

@CSEKU160212
Copy link

CSEKU160212 commented Jul 9, 2023

All command executed successfully but getting below error: (On macbook M2)

PHP 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

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: Jun 17 2023 06:19:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

Checked the location and found oci8.so.
What to do now??

@NALAWALAMURTUZA
Copy link

same issue facing @CSEKU160212 in mac book M1

@CSEKU160212
Copy link

@NALAWALAMURTUZA , I have stopped trying to solve this issue, I think for M1 and m2, there is no oracle support. I have installed UTM and installed windows on the virtual machine for this kind of service.

@ilyas-gx
Copy link

@CSEKU160212 & @NALAWALAMURTUZA , this guide is for Catalina (which is x86, it doesn't support Apple Sillicon). There is no way to compile oci8.so on M1/M2 natively but you can emulate it through rosetta.

@syahzul
Copy link
Author

syahzul commented Aug 10, 2023

Try this one for M1 https://gist.github.com/syahzul/adfac83e1d930f400855b5425564dfda

I haven't tried with M2 since I don't have the device

@syahzul
Copy link
Author

syahzul commented Aug 10, 2023

@CSEKU160212 & @NALAWALAMURTUZA , this guide is for Catalina (which is x86, it doesn't support Apple Sillicon). There is no way to compile oci8.so on M1/M2 natively but you can emulate it through rosetta.

Yes, thank you.

@syahzul
Copy link
Author

syahzul commented Sep 27, 2023

@CSEKU160212 please refer https://gist.github.com/syahzul/473ef51b61d82f1f5e294bf5cb804fed for macOS Ventura or Sonoma on M1 or M2.

@Pedroletti-Michael
Copy link

Hey, just writing here because I had some issues with the installation. And for troubleshooting the problems I had to look for the path where the oci8.so (this info was find during the end of the command pecl install, it say something like "Libraries have been installed in : path) was installed and just copy the path to the php.ini on the line extension_dir="/path/to/oci8.so".

Have a nice day 👍

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