Caution
Finally Oracle release Instant Client for arm64 architecture. Refer new tutorial How to install PHP OCI8 for macOS Ventura/Sonoma on Apple Silicon Macs (arm64 version) here.
Note
If your using macOS Monterey or below, please refer to How to install OCI8 on macOS (Monterey) M1 Processor with PHP 8.1
macOS Ventura and above, duplicating and renaming Terminal.app are disabled by Apple. In order to install the OCI8, we need to switch between arm64 and x86_64 architecture.
In Terminal, there is no automatic detection for missing Rosetta to run older architecture command line tools.
If you haven't been prompted for any other app already, manually install Rosetta 2:
softwareupdate --install-rosetta
Open the Terminal and run the following codes to add aliases to switch between architecture.
echo "alias intel='env /usr/bin/arch -x86_64 /bin/zsh --login'" >> ~/.zshrc
echo "alias arm='env /usr/bin/arch -arm64 /bin/zsh --login'" >> ~/.zshrc
Close and re-open the Terminal and run the following command:
arm
arch
Make sure our current architecture is arm64.
Run the command below if you haven't installed it on your machine.
xcode-select --install
If you have installed the Homebrew for Apple Silicon previously, remove it. To uninstall, open the Terminal and use the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Run the following command to switch to i386:
intel
arch
Make sure our current architecture is i386.
Run the following command to start installing Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installation completed, verify that we have installed Intel version, not Apple Silicon by using the command below:
which brew
If the output is /usr/local/bin/brew
, then it's for Intel.
But if the output is /opt/homebrew/bin/brew
, it's for Apple Silicon. You have to start all over again by uninstalling it using the steps above.
Download the following files from Oracle Instant Client Downloads for macOS (Intel x86)
Create a folder for the files.
sudo mkdir -p /opt/oracle/instantclient
Now, extract the .dmg files and move the contents to /opt/oracle/instantclient
.
Wen can proceed to install the latest version of PHP (which is 8.3 at the moment) and the dependencies. It may take a while to complete.
brew install php
Verify the PHP version installed on our machine.
php -v
PHP 8.3.3 (cli) (built: Feb 13 2024 15:41:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.3, Copyright (c) Zend Technologies
with Zend OPcache v8.3.3, Copyright (c), by Zend Technologies
Install the latest version of oci8 (v3.3.0) with PECL.
echo instantclient,/opt/oracle/instantclient | pecl install oci8
Note:
- 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 Instant Client files since the developer cannot be verified. We have to allow it one by one.
Open your System Settings
> Privacy & Security
> Security
, and keep it open, don't close it.
Run the command below to trigger the warning.
php -m
macOS will pop up the warning dialog, click on Open
(if available) or Cancel
, and click Allow Anyway
on your Privacy & Security
window. You might have to do it a few times until no more warning dialog appears.
Run the command to make sure oci8 is enabled.
php -m | grep oci8
Create a file containing the following codes.
<?php
if (function_exists('oci_connect')) {
echo 'OCI8 is working!';
} else {
echo 'Whoopss...not working!';
}
Finally! Thanks for the info.