Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save syahzul/d61d8ccea7c5959a84ed52d14159d8a9 to your computer and use it in GitHub Desktop.
Save syahzul/d61d8ccea7c5959a84ed52d14159d8a9 to your computer and use it in GitHub Desktop.
How to install PHP OCI8 for macOS Ventura/Sonoma on Apple Silicon Macs (arm64 version)

How to install PHP OCI8 for macOS Ventura/Sonoma on Apple Silicon Macs (arm64 version)

This tutorial will guide you on how to install OCI8 for PHP8.3 using Oracle Instant Client arm64.

1. Install Command Line Tools for Xcode

Run the command below if you haven't installed it on your machine.

xcode-select --install

2. Install Homebrew

Run the following command to start installing Homebrew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Verify your brew installation using the command below:

which brew

You should get /opt/homebrew/bin/brew as the output.

Warning

If you got notice brew not found, you need to add /opt/homebrew/bin to your environment path. Simply add export PATH="/opt/homebrew/bin:$PATH" to your .zshrc file.

3. Oracle Instant Client for macOS (arm64)

Download the following files from Oracle Instant Client Downloads for macOS (arm64)

Create a folder for the files.

sudo mkdir -p /opt/oracle/instantclient_23_3

Now, extract both .dmg files and move the contents to /opt/oracle/instantclient_23_3.

4. Install PHP

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.8 (cli) (built: Jun  4 2024 14:53:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies

5. Install PHP OCI8

Install the latest version of oci8 (v3.3.0) with PECL.

echo instantclient,/opt/oracle/instantclient_23_3 | pecl install oci8

Warning

If you ever got an error command not found: pecl, make sure PHP bin folder is included in your environment path.

Note

Use the appropriate version of oci8 for your PHP. Refer https://pecl.php.net/package/oci8 for more info.

6. Allows Instant Client files run on macOS

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

7. Test it out

Create a file containing the following codes.

<?php
if (function_exists('oci_connect')) {
    echo 'OCI8 is working!';
} else {
    echo 'Whoopss...not working!';
}

8. References

  1. How to install PHP OCI8 for macOS Ventura/Sonoma on Apple Silicon Macs
  2. How to install OCI8 on macOS (Monterey) M1 Processor with PHP 8.1
  3. M1 Mac — How to switch the Terminal between x86_64 and arm64
@syahzul
Copy link
Author

syahzul commented Jul 22, 2024

i cannot replicate your issue, but can you try this solution and hopefully it helps.

https://patriqueouimet.ca/tip/installing-php-and-pecl-extensions-on-macos

@meshackjr
Copy link

Kudos 👏

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