Note
If your using macOS Ventura or Sonoma, please refer to How to install PHP OCI8 for macOS Ventura/Sonoma on Apple Silicon Macs
Please note that all installations below must use Terminal with Rosetta:
- Homebrew Intel Mac Version
- PHP 8.1 or 8.0
- OCI8 extension
And use Terminal without Rosetta for:
- Installing Command Line Tools for Xcode
- Uninstalling Homebrew M1 version
Duplicate Terminal that located under /Applications/Utilities and renames it to Terminal-Rosetta.
Right click on Terminal-Rosetta > Get Info > Open using Rosetta.
Run it once and macOS will prompt to install Rosetta on your machine. Once completed, re-open your Terminal-Rosetta.
Run the command below if you haven't installed it on your machine.
xcode-select --installIf you have installed the Homebrew for M1 processor previously, remove it. To uninstall, open Terminal (running without Rosetta) and use the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"Install the Homebrew using Terminal-Rosetta.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Create a folder to store Oracle Instant Client files.
sudo mkdir /opt/oracleDownload the following files from Oracle website
Unzip and move it to the /opt/oracle/instantclient_19_8.
sudo mkdir -p /usr/local/{include,lib}
sudo ln -s /opt/oracle/instantclient_19_8/sdk/include/*.h /usr/local/include/
sudo ln -s /opt/oracle/instantclient_19_8/*.dylib /usr/local/lib/
sudo ln -s /opt/oracle/instantclient_19_8/*.dylib.19.1 /usr/local/lib/
sudo ln -s /usr/local/lib/libclntsh.dylib.19.1 /usr/local/lib/libclntsh.dylibInstall PHP and the dependencies. It may take a while to complete.
brew install phpVerify the PHP version installed on your machine.
php -v
PHP 8.1.10 (cli) (built: Sep 3 2022 12:09:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
with Zend OPcache v8.1.10, Copyright (c), by Zend Technologies
Install the latest version of oci8 (v3.2.1) with PECL.
echo instantclient,/opt/oracle/instantclient_19_8 | pecl install oci8Install PHP and the dependencies. It may take a while to complete.
brew install php@8.0Verify the PHP version installed on your machine.
php -v
PHP 8.0.23 (cli) (built: Sep 4 2022 09:20:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.23, Copyright (c) Zend Technologies
with Zend OPcache v8.0.23, Copyright (c), by Zend Technologies
Install oci8 version 3.0.1 with PECL.
echo instantclient,/opt/oracle/instantclient_19_8 | pecl install oci8-3.0.1Install PHP and the dependencies. It may take a while to complete.
brew install php@7.4Verify the PHP version installed on your machine.
php -v
PHP 7.4.30 (cli) (built: Sep 4 2022 09:01:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies
Install oci8 version 2.2.0 with PECL.
echo instantclient,/opt/oracle/instantclient_19_8 | pecl install oci8-2.2.0Note:
- If you ever got an error
command not found: pecl, make sure PHP bin folder is included in your environment path. - Use the appropriate version of oci8 for your PHP. Refer https://pecl.php.net/package/oci8 for more info.
By default, macOS will block the files since the developer cannot be verified. Open your System Preferences > Security & Privacy > General, and keep it open, then run the command below:
php -mmacOS will pop up the warning, just click Open (if available) or Cancel, and click Allow Anyway on your Security & Privacy window.
Re-run the command above until no more warning and make sure oci8 is on the list.
php -m | grep oci8Create a file containing the following codes.
<?php
if (function_exists('oci_connect')) {
echo 'OCI8 is working!';
}
else {
echo 'Whoopss...not working!';
}- Not working for macOS Ventura and Sonoma. Refer here
nice. will try it out later on.