Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nasrulhazim/308c9f59a2ddba364b4b908ee9238265 to your computer and use it in GitHub Desktop.
Save nasrulhazim/308c9f59a2ddba364b4b908ee9238265 to your computer and use it in GitHub Desktop.
install Oracle PHP Extension (oracle OCI8) - instantclient for Mac OS 10.12.6 - homebrew environnement - on PHP 7.2

Installation

This procedure is tested on Mac OS X 10.12.6

PHP 7.2 installed with Homebrew.

Preparation

Download the following files from Oracle website (yes, you need to create an account and accept terms):

Create and unzip all theses files into a the directory /usr/local/instantclient/12.2.0.1/.

Create symlinks

sudo ln -sfn /usr/local/instantclient/12.2.0.1/sdk/include/*.h /usr/local/include/
sudo ln -sfn /usr/local/instantclient/12.2.0.1/sqlplus /usr/local/bin/
sudo ln -sfn /usr/local/instantclient/12.2.0.1/*.dylib /usr/local/lib/
sudo ln -sfn /usr/local/instantclient/12.2.0.1/*.dylib.12.1 /usr/local/lib/
sudo ln -sfn /usr/local/lib/libclntsh.dylib.12.1 /usr/local/lib/libclntsh.dylib

Install extension with pecl

pecl install oci8

On success installation, you will have messages like the following:

Build process completed successfully
Installing '/usr/local/Cellar/php/7.2.7/pecl/20170718/oci8.so'
install ok: channel://pecl.php.net/oci8-2.1.8
Extension oci8 enabled in php.ini

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

instantclient,/usr/local/lib

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:

Run php --ini to check your php.ini file location.

extension=oci8.so

Then do test the setup by running php -v.

If you are having error code like the following:

Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /usr/local/Cellar/php/7.2.7/lib/php/20170718/oci8.so (dlopen(/usr/local/Cellar/php/7.2.7/lib/php/20170718/oci8.so, 9): image not found), /usr/local/Cellar/php/7.2.7/lib/php/20170718/oci8.so.so (dlopen(/usr/local/Cellar/php/7.2.7/lib/php/20170718/oci8.so.so, 9): image not found)) in Unknown on line 0

You can copy the oci8.so generated to the target path. In above case as following:

cp /usr/local/Cellar/php/7.2.7/pecl/20170718/oci8.so /usr/local/Cellar/php/7.2.7/lib/php/20170718/

Then you should see no more error message when runninng php -v.

Restart your HTTP Server and test.

Enjoy (or try to...) !

@masterkitano
Copy link

Bro this super clear and awesome guide saved me hours or days of configuration!!! Really appreciate it. I owe you a beer! stay safe.

@nasrulhazim
Copy link
Author

@nasrulhazim
Copy link
Author

A bit different the process to install 19.8.

Download Basic MacOS DMG

Double click the .dmg file.

Then in terminal:

$ cd /Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru
$ ./install_ic.sh

Next you want to install the SQPlus and the SDK

$ cd $HOME/Downloads

$ curl -O https://download.oracle.com/otn_software/mac/instantclient/198000/instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg
$ curl -O https://download.oracle.com/otn_software/mac/instantclient/198000/instantclient-sqlplus-macos.x64-19.8.0.0.0dbru.dmg

$ hdiutil mount instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg
$ hdiutil mount instantclient-sqlplus-macos.x64-19.8.0.0.0dbru.dmg

$ /Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru/install_ic.sh

$ hdiutil unmount /Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru
$ hdiutil unmount /Volumes/instantclient-sqlplus-macos.x64-19.8.0.0.0dbru

Then you may want to retain the previous instant client version structure in /usr/local/instantclient, you can simply copy the configured instantclient file to the respective directory:

$ cp $HOME/Downloads/instantclient_19_8 /usr/local/instantclient/19.8.0.0.0

The next steps just make sure to symlink, install pecl install oci8-2.2.0 (if using php 7), else use php install oci for those using PHP8.

Then you are done.

@rbenosa
Copy link

rbenosa commented Nov 26, 2021

@nasrulhazim

Hi, will this work on M1 chip with macOS Monterey.?

thanks

@nasrulhazim
Copy link
Author

@rbenosa didn't try yet on M1 / Monterey. But will have a look on it, since I have a project using Oracle - but not yet started on that.

@rbenosa
Copy link

rbenosa commented Nov 29, 2021

@rbenosa didn't try yet on M1 / Monterey. But will have a look on it, since I have a project using Oracle - but not yet started on that.

@nasrulhazim

I see, If ever you were able to do it can you please share it here.

thanks.

@pwnz22
Copy link

pwnz22 commented Dec 3, 2021

I'm having an error after installing on M1

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), '/usr/local/lib/oci8.so.so' (no such file), '/usr/lib/oci8.so.so' (no such file))) in Unknown on line 0

Any solutions?

@VextroPal
Copy link

I'm having an error after installing on M1
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), '/usr/local/lib/oci8.so.so' (no such file), '/usr/lib/oci8.so.so' (no such file))) in Unknown on line 0
Any solutions?

i got the same problem, any solution with this ?

@afzal415
Copy link

i am having the same problem

@nasrulhazim
Copy link
Author

nasrulhazim commented Jan 14, 2022

I've tried, using the following steps:

sudo su
cd /opt
mkdir oracle 
mv /Users/nasrulhazim/Downloads/instantclient-* /opt/oracle 
unzip instantclient-basic-macos.x64-19.8.0.0.0dbru.zip
unzip instantclient-sdk-macos.x64-19.8.0.0.0dbru.zip
unzip instantclient-sqlplus-macos.x64-19.8.0.0.0dbru.zip
unzip instantclient-tools-macos.x64-19.8.0.0.0dbru.zip
cd /opt/oracle/instantclient_19_8
ln -s /opt/oracle/instantclient_19_8/sqlplus /usr/local/bin/
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.12.1 /usr/local/lib/
ln -s /opt/oracle/instantclient_19_8/*.dylib.19.1 /usr/local/lib/
curl -O https://pear.php.net/go-pear.phar

Edit /etc/profile and add the following:

$ nano /etc/profile
export ORACLE_HOME=/opt/oracle/instantclient_19_8
export DYLD_LIBRARY_PATH=/opt/oracle/instantclient_19_8
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_8

Install OCI8. I'm using version 3.0.1 because I'm having PHP 8.0.13. If you are running on PHP 8.1, you don't need to provide the version.

$ pecl install oci8-3.0.1
Enter: instantclient,/usr/local/lib

And yes, having similar issue.

Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /opt/homebrew/lib/php/pecl/20200930/oci8.so (dlopen(/opt/homebrew/lib/php/pecl/20200930/oci8.so, 0x0009): symbol not found in flat namespace '_OCIAttrGet'), /opt/homebrew/lib/php/pecl/20200930/oci8.so.so (dlopen(/opt/homebrew/lib/php/pecl/20200930/oci8.so.so, 0x0009): tried: '/opt/homebrew/lib/php/pecl/20200930/oci8.so.so' (no such file), '/usr/local/lib/oci8.so.so' (no such file), '/usr/lib/oci8.so.so' (no such file))) in Unknown on line 0

The only option for now is to run your application in Docker.

@Bosphoramus
Copy link

:( Knowing Oracle they will never release a M1 compiled version, they simply dont care... and there isnt even a way to send a ticket asking for support...
this is sad af 😕

@pwnz22
Copy link

pwnz22 commented Jan 21, 2022

I resolved issue installing a brew version with rosetta and installing oci8 with rosetta terminal as well

@Bosphoramus
Copy link

A brew version of what? Instant client? And whats the oci8 package name on brew, “oci8”?
I would appreciate if you could guide me a little 🤩

@pwnz22
Copy link

pwnz22 commented Jan 21, 2022

Homebrew under the rosetta 2 follow this link

@VextroPal
Copy link

@pwnz22 I resolved issue installing a brew version with rosetta and installing oci8 with rosetta terminal as well

hey can you make guide for it? i really appreciate it if you can do it

@gothaussencl
Copy link

Hi! @pwnz22 please u can make guide por it? i can't install with rosetta :( help us please

@pwnz22
Copy link

pwnz22 commented Apr 5, 2022

If you have brew already installed (for M1 chips it's installed on /opt/homebrew) you must delete it and install it with Rosetta terminal to /usr/local, after that you can install packages for intel. That's all

@nasrulhazim
Copy link
Author

If you have brew already installed (for M1 chips it's installed on /opt/homebrew) you must delete it and install it with Rosetta terminal to /usr/local, after that you can install packages for intel. That's all

Is it? that's all? probably gonna try later.

@Element7
Copy link

If you have brew already installed (for M1 chips it's installed on /opt/homebrew) you must delete it and install it with Rosetta terminal to /usr/local, after that you can install packages for intel. That's all

Thank you :) It is all working now 👍

@oldevill14
Copy link

oldevill14 commented Feb 2, 2023

This procedure is tested on Mac OS X Ventura 13.2

PHP 8.1

1> M1 chips enable rosetta2

2> download oracle
2.1>instantclient-basic-macos.x64-19.8.0.0.0dbru.zip
2.2>instantclient-sdk-macos.x64-19.8.0.0.0dbru.zip
2.3>instantclient-sqlplus-macos.x64-19.8.0.0.0dbru.zip

3> unzip to $HOME/Downloads/instantclient_19_8

4> Download mac instantclient
4.1> cd $HOME/Downloads
4.2> curl -O https://download.oracle.com/otn_software/mac/instantclient/instantclient-basic-macos.zip
4.3> curl -O https://download.oracle.com/otn_software/mac/instantclient/instantclient-sdk-macos.zip

5> unzip mac instantclient
5.1> cd $HOME/Downloads/
5.2> sudo unzip $HOME/Downloads//instantclient-basic-macos.zip
5.3> sudo unzip $HOME/Downloads//instantclient-sdk-macos.zip

6> remove new libraries not needed by OCI8
6.1> sudo rm -f $HOME/Downloads/instantclient_19_8/{jdbc,occi,mysql,*jar,uidrvci,genezi,adrci}

7> copy lib to /usr/local/bin/
ln -s $HOME/Downloads/instantclient_19_8/sqlplus /usr/local/bin/
ln -s $HOME/Downloads/instantclient_19_8/sdk/include/.h /usr/local/include/
ln -s $HOME/Downloads/instantclient_19_8/
.dylib /usr/local/lib/
ln -s $HOME/Downloads/instantclient_19_8/.dylib.12.1 /usr/local/lib/
ln -s $HOME/Downloads/instantclient_19_8/
.dylib.19.1 /usr/local/lib/

8> pecl install oci8
8.1> instantclient,/usr/local/lib

9> check "php -m" => oci8 !!!

@NALAWALAMURTUZA
Copy link

NALAWALAMURTUZA commented Aug 2, 2023

@ALL any one have a solution please share it for Mac M1 chip. I m facing the same error.

Warning: PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /opt/homebrew/lib/php/pecl/20220829/oci8.so (dlopen(/opt/homebrew/lib/php/pecl/20220829/oci8.so, 0x0009): tried: '/opt/homebrew/lib/php/pecl/20220829/oci8.so' (errno=20), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/php/pecl/20220829/oci8.so' (no such file), '/opt/homebrew/lib/php/pecl/20220829/oci8.so' (errno=20)), /opt/homebrew/lib/php/pecl/20220829/oci8.so.so (dlopen(/opt/homebrew/lib/php/pecl/20220829/oci8.so.so, 0x0009): tried: '/opt/homebrew/lib/php/pecl/20220829/oci8.so.so' (errno=20), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/php/pecl/20220829/oci8.so.so' (no such file), '/opt/homebrew/lib/php/pecl/20220829/oci8.so.so' (errno=20))) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'oci8.so' (tried: /opt/homebrew/lib/php/pecl/20220829/oci8.so (dlopen(/opt/homebrew/lib/php/pecl/20220829/oci8.so, 0x0009): tried: '/opt/homebrew/lib/php/pecl/20220829/oci8.so' (errno=20), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/php/pecl/20220829/oci8.so' (no such file), '/opt/homebrew/lib/php/pecl/20220829/oci8.so' (errno=20)), /opt/homebrew/lib/php/pecl/20220829/oci8.so.so (dlopen(/opt/homebrew/lib/php/pecl/20220829/oci8.so.so, 0x0009): tried: '/opt/homebrew/lib/php/pecl/20220829/oci8.so.so' (errno=20), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/php/pecl/20220829/oci8.so.so' (no such file), '/opt/homebrew/lib/php/pecl/20220829/oci8.so.so' (errno=20))) in Unknown on line 0

same issue

https://gist.github.com/syahzul/2632262df21974ecd02be3ccce66fbef

@akhiidwandhare
Copy link

@oldevill14
I followed all steps but getting error something like this.
Can you help me out here please.

Screenshot 2023-12-14 at 17 18 46

@abdulwahhabkhan
Copy link

Hi tried to install and everything look working except.

php -m

image

php -i

image

any idea what can be the reason?

Install oracle client and sqlplus user/password@localhost/service working.

@oldevill14
Copy link

@akhiidwandhare @abdulwahhabkhan

Mac OS current version is also not available to me.

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