After some research, it seems that the Oracle OCI8 extension is not yet compatible with PHP 8.1 and 8.2 on Apple Silicon. However, there is a workaround that involves using Docker to run a Linux container with PHP 7.4 and the OCI8 extension installed.
Here are the steps to follow:
-
Install Docker Desktop for Mac on your Apple Silicon machine.
-
Create a new directory for your project and navigate to it in the terminal.
-
Create a new file called
Dockerfilewith the following contents:
FROM php:7.4-cli
RUN apt-get update && \
apt-get install -y libaio1 unzip && \
mkdir /opt/oracle && \
cd /opt/oracle && \
curl -o instantclient-basic-linux.x64-19.8.0.0.0dbru.zip https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip && \
curl -o instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip && \
unzip instantclient-basic-linux.x64-19.8.0.0.0dbru.zip && \
unzip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip && \
rm -f instantclient-basic-linux.x64-19.8.0.0.0dbru.zip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip && \
echo /opt/oracle/instantclient_19_8 > /etc/ld.so.conf.d/oracle-instantclient.conf && \
ldconfig
RUN pecl install oci8-2.2.0 && \
docker-php-ext-enable oci8
WORKDIR /var/www/html
This Dockerfile will create a new container based on the official PHP 7.4 image, install the Oracle Instant Client and OCI8 extension, and set the working directory to /var/www/html.
- Build the Docker image by running the following command in the terminal:
docker build -t my-php-app .
This will create a new Docker image called my-php-app based on the Dockerfile in the current directory.
- Run the Docker container by running the following command in the terminal:
docker run -it --rm -v $(pwd):/var/www/html my-php-app
This will start a new container based on the my-php-app image, mount the current directory as the document root, and open an interactive terminal session.
- Test the OCI8 extension by running the following command in the terminal:
php -r 'var_dump(extension_loaded("oci8"));'
This should output bool(true) if the extension is installed and loaded correctly.
You can now develop your application inside the Docker container and connect to the Oracle database using the OCI8 extension.
Note: This workaround is not ideal and may have some performance overhead due to running inside a container. It is recommended to switch back to Valet once the OCI8 extension is compatible with PHP 8.1 and 8.2 on Apple Silicon.