How to Install Oracle Driver for PHP on Ubuntu 18.04
Oracle Database, or more commonly referred to only as Oracle, is a Relational Database Management System (RDBMS) type, which is a proprietary database from Oracle Corporation. The PHP programming language can use Oracle, but by default PHP on Ubuntu 18.04 is not yet available for Oracle driver, so you have to install it manually.
0. Requirements
Ubuntu 18.04 must be installed using Apache and PHP (7.2).
1.Install Oracle Driver
Download Oracle instantclient here. Then upload to the server.
- instantclient-basic-linux.x64-12.2.0.1.0.zip
- instantclient-sdk-linux.x64-12.2.0.1.0.zip
Extract files that have been uploaded on the server.
1 2 | unzip instantclient-basic-linux.x64-12.2.0.1.0.zip unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip |
Create oracle folder.
1 | mkdir /opt/oracle |
Move and rename the instantclient folder.
1 | mv instantclient_12_2 /opt/oracle/instantclient |
Change folder ownership.
1 | chown -R root:www-data /opt/oracle |
Install dependencies needed to install OCI8 (Oracle Instant Client 8).
1 | apt install php7.2-dev php-pear build-essential libaio1 |
Make a symbolic link.
1 2 | ln -s /opt/oracle/instantclient/libclntsh.so.12.1 /opt/oracle/instantclient/libclntsh.so ln -s /opt/oracle/instantclient/libocci.so.12.1 /opt/oracle/instantclient/libocci.so |
Add an instant client to ldconfig.
1 | echo /opt/oracle/instantclient > /etc/ld.so.conf.d/oracle-instantclient.conf |
Update Dynamic Linker Run-Time Bindings
1 | ldconfig |
Install oci8.
1 | pecl install oci8 |
Showing questions
1 | Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] : |
Answer with
1 | instantclient,/opt/oracle/instantclient |
Add OCI8 to cli php config.
1 | echo "extension = oci8.so" >> /etc/php/7.2/cli/php.ini |
Add OCI8 to Apache PHP Config.
1 | echo "extension = oci8.so" >> /etc/php/7.2/apache2/php.ini |
Set environement variables for cli (The server must be restarted)
1 2 | echo "LD_LIBRARY_PATH=\"/opt/oracle/instantclient\"" >> /etc/environment echo "ORACLE_HOME=\"/opt/oracle/instantclient\"" >> /etc/environment |
Set environement variables for apache.
1 2 | echo "export LD_LIBRARY_PATH=\"/opt/oracle/instantclient\"" >> /etc/apache2/envvars echo "export ORACLE_HOME=\"/opt/oracle/instantclient\"" >> /etc/apache2/envvars |
Restart apache
1 | systemctl restart apache2 |
2.Testing
Create info.php file.
1 | echo "<?php phpinfo(); ?>" > /var/www/html/info.php |
Browse http://IP-SERVER/info.php, find oci8.
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin