Source: http://www.syahzul.com/2016/04/06/how-to-install-oci8-on-ubuntu-14-04-and-php-5-6/
Download the Oracle Instant Client and SDK from Oracle website. (Need to login in Oracle page)
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
Files: instantclient-basic-linux.x64-12.2.0.1.0.zip
and instantclient-sdk-linux.x64-12.2.0.1.0.zip
.
Create a new folder to store Oracle Instant Client zip files on your server.
Upload the Instant Clients files inside this folder.
mkdir /opt/oracle
Now we need to extract the files.
cd /opt/oracle
unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip
Next, we need to create a symlink to Instant Client files.
ln -s /opt/oracle/instantclient_12_2/libclntsh.so.12.1 /opt/oracle/instantclient_12_2/libclntsh.so
ln -s /opt/oracle/instantclient_12_2/libocci.so.12.1 /opt/oracle/instantclient_12_2/libocci.so
Add the folder to our ldconfig
.
echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient
Update the Dynamic Linker Run-Time Bindings
ldconfig
Done. Now we can proceed to the next part.
To install the OCI8 extension, we need to install some additional package on our server.
Run these command:
apt-get install php-dev php-pear build-essential libaio1
Once installed, we need to get the OCI8 file. But, before that we need to update PECL channel.
pecl channel-update pecl.php.net
Then.
pecl install oci8
When you are prompted for the Instant Client location, enter the following:
instantclient,/opt/oracle/instantclient_12_2
We need to tell PHP to load the OCI8 extension.
echo "extension =oci8.so" >> /etc/php/7.2/fpm/php.ini
echo "extension =oci8.so" >> /etc/php/7.2/cli/php.ini
echo "extension =oci8.so" >> /etc/php/7.2/apache2/php.ini
We also need to add on apache those environment variables.
echo "export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2" >> /etc/apache2/envvars
echo "export ORACLE_HOME=/opt/oracle/instantclient_12_2" >> /etc/apache2/envvars
echo "LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH" >> /etc/environment
Refresh the server. If you are accessing through SSH, then
exit
or
sudo shutdown -r now
Check if the extension is enabled.
php -m | grep 'oci8'
If returns oci8
, its works!
Restart the PHP-FPM
service php7.2-fpm restart
Now you can connect to Oracle DBMS from your PHP applications.
I was able to get it working on PHP 8.2 using Docker. I downloaded the needed ZIP files and added them to my docker/ folder. This is the part from Docker:
Install Oracle Instantclient
RUN mkdir /opt/oracle
COPY ./docker/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip /opt/oracle
COPY ./docker/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip /opt/oracle
COPY ./docker/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip /opt/oracle
RUN unzip /opt/oracle/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle
&& unzip /opt/oracle/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle
&& unzip /opt/oracle/instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle
&& rm -rf /opt/oracle/*.zip
&& mv /opt/oracle/instantclient_21_6 /opt/oracle/instantclient
ARG ORACLE_HOME=/opt/oracle/
ENV ORACLE_HOME=/opt/oracle/
ARG LD_LIBRARY_PATH=/opt/oracle/instantclient/
ENV LD_LIBRARY_PATH /opt/oracle/instantclient:${LD_LIBRARY_PATH}
RUN ldconfig
for PHP 8.2
#RUN echo 'instantclient,/opt/oracle/instantclient' | pecl install oci8
for PHP 8.1
RUN echo 'instantclient,/opt/oracle/instantclient' | pecl install oci8-3.2.1
Install Oracle extensions
RUN docker-php-ext-enable oci8
&& docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/opt/oracle/instantclient
&& docker-php-ext-install pdo_oci