This text is intended to guide the installation and configuration of Oracle's InstantClient, responsible for mediating connections with Oracle databases. Below are the necessary steps::
This tutorial adopted version 8.1 of PHP. If your version is different, make the necessary adaptations.
The terminal adopted is the default one, so the configuration of environment variables is done in
~/.bashrc
. If using ZSH, add the variables in~/.zshrc
Download Oracle Instant Client (Base Client and SDK Package):
mkdir ~/Downloads cd ~/Downloads sudo wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip sudo wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip
Create a folder called oracle inside the address /opt/
and extract the files to it:
sudo mkdir /opt/oracle cd /opt/oracle sudo unzip ~/Downloads/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle sudo unzip ~/Downloads/instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -d /opt/oracle
Rename the generated folder with the version to just instantclient, otherwise when updating the package version it will be necessary to redo the tutorial:
sudo mv instantclient_21_6 instantclient
Add a folder to ldconfig
and update the linked linker:
sudo -i echo "/opt/oracle/instantclient" > /etc/ld.so.conf.d/oracle-instantclient echo "/opt/oracle/instantclient" >> /etc/ld.so.conf.d/x86_64-linux-gnu.conf ldconfig
Instale as dependências do PHP que comunicam com o sdk da Oracle:
sudo apt install php8.1-dev php-pear build-essential libaio1
obs: In case of dependency failures in the installation of packages, run the command sudo apt-get -f install
Get the oci8 library file and set the InstantClient location when prompted:
pecl install oci8-3.0.1 instantclient,/opt/oracle/instantclient pecl channel-update pecl.php.net
Add PHP extensions:
Extensões PHP:
echo "extension = oci8.so" >> /etc/php/8.1/fpm/php.ini echo "extension = oci8.so" >> /etc/php/8.1/cli/php.ini systemctl restart php8.1-fpm systemctl restart apache2 exit
Test if the extension is enabled:
php -m | grep 'oci8'
obs: The result should be something like oci8
Configure the environment variables needed to link the InstantClient:
echo "export LD_LIBRARY_PATH=/opt/oracle/instantclient/" >> ~/.bashrc echo "export ORACLE_HOME=/opt/oracle/instantclient/network/admin/" >> ~/.bashrc echo "export TNS_ADMIN=/opt/oracle/instantclient/network/admin/" >> ~/.bashrc source ~/.bashrc
Or with ZSH
echo "export LD_LIBRARY_PATH=/opt/oracle/instantclient/" >> ~/.zshrc echo "export ORACLE_HOME=/opt/oracle/instantclient/network/admin/" >> ~/.zshrc echo "export TNS_ADMIN=/opt/oracle/instantclient/network/admin/" >> ~/.zshrc source ~/.zshrc
Ready. It should now be possible to connect to Oracle DBMS from your PHP applications