This procedure is tested on Mac OS X 10.12.6
PHP 7.2 installed with Homebrew.
Download the following files from Oracle website (yes, you need to create an account and accept terms):
- instantclient-basic-macos.x64-12.2.0.1.0-2.zip
- instantclient-sqlplus-macos.x64-12.2.0.1.0-2.zip
- instantclient-sdk-macos.x64-12.2.0.1.0-2.zip
Create and unzip all theses files into a the directory /usr/local/instantclient/12.2.0.1/
.
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
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 yourphp.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...) !
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 !!!