Adding Oracle Support PHP On Ubuntu Xenial
I’ve been recently asked to enable a web server running to PHP to connect to an Oracle database for a client. Sadly this doesn’t work natively on FreeBSD so I’m documenting how I managed to do it on Ubuntu Xenial. This was inspired by this post and this post .
Update System:
1apt-get update
2apt-get upgrade
3apt-get dist-upgrade
4apt-get install zip
5reboot
Download Instant Client drivers:
Download the files below from Oracle
1instantclient-basic-linuxAMD64-10.1.0.5.0-20060519.zip
2instantclient-sdk-linuxAMD64-10.1.0.5.0-20060519.zip
3instantclient-sqlplus-linuxAMD64-10.1.0.5.0-20060519.zip
Prepare installation location:
Create the folder as below and upload the Instant Client files to that location
1mkdir /opt/oracle
Extract files:
1cd /opt/oracle
2unzip instantclient-basic-linuxAMD64-10.1.0.5.0-20060519.zip
3unzip instantclient-sdk-linuxAMD64-10.1.0.5.0-20060519.zip
4unzip instantclient-sqlplus-linuxAMD64-10.1.0.5.0-20060519.zip
5mv instantclient10_1 instantclient
Update ldconfig:
Create symlinks to the so files
1cd instantclient
2ln -s libclntsh.so.10.1 libclntsh.so
3ln -s libocci.so.10.1 libocci.so
Run ldconfig
1echo /opt/oracle/instantclient > /etc/ld.so.conf.d/oracle-instantclient.conf
2ldconfig -v
Prepare and test connectivity:
Add the following to the end of .bashrc
1export PATH=$PATH:/opt/oracle/instantclient
2export ORACLE_HOME="/opt/oracle/instantclient"
3export OCI_LIB="/opt/oracle/instantclient"
4export TNS_ADMIN="/opt/oracle/instantclient/network/admin"
Reload .bashrc:
1source ~/.bashrc
Create the tnsnames.ora file
1mkdir -p /opt/oracle/instantclient/network/admin
Contents:
1# /opt/oracle/instantclient/network/admin/tnsnames.ora
2MYDATABASE=
3 (description=
4 (address_list=
5 (address = (protocol = TCP)(host = IPADDRESS)(port = PORT))
6 )
7 (connect_data =
8 (service_name=DATABASESID)
9 )
10)
Test:
1sqlplus USER/PASSDWORD@MYDATABASE
This is what you should see if everything was successful:
1SQL*Plus: Release 10.1.0.5.0 - Production on Mon Apr 24 05:05:49 2017
2
3Copyright (c) 1982, 2005, Oracle. All rights reserved.
4
5
6Connected to:
7Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
8With the Partitioning, OLAP, Data Mining and Real Application Testing options
9
10SQL>
Install the required packages to compile OCI8:
1apt-get install php-pear php-dev build-essential libaio1
Install OCI8 through pecl
1pecl install oci8
Answer with the following:
1Client [autodetect] : instantclient,/opt/oracle/instantclient
Add to the available PHP modules
1echo extension=oci8.so > /etc/php/7.0/mods-available/oci8.ini
Enable the extension (Here we will do it for CLI)
1ln -s /etc/php/7.0/mods-available/oci8.ini /etc/php/7.0/cli/conf.d/
Check if the module was indeed enabled
1php -m
2[PHP Modules]
3calendar
4Core
5ctype
6date
7dom
8exif
9fileinfo
10filter
11ftp
12gettext
13hash
14iconv
15json
16libxml
17oci8
18openssl
19pcntl
20pcre
21PDO
22Phar
23posix
24readline
25Reflection
26session
27shmop
28SimpleXML
29sockets
30SPL
31standard
32sysvmsg
33sysvsem
34sysvshm
35tokenizer
36wddx
37xml
38xmlreader
39xmlwriter
40xsl
41Zend OPcache
42zlib
43
44[Zend Modules]
45Zend OPcache
Congratulations. You are now done :)
About Me
Dev gone Ops gone DevOps. Any views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.
Recent Posts