Using Oracle Autonomous database with PHP

The Oracle Cloud free tier is pretty generous, one thing that stands out is the free tier for a managed database.  Normally I would use mysql , but this is oracle and I haven't used that in a long time.  I also haven't used it with PHP

These are my notes to make it work on ubuntu

overview:
1. download and install oracle client and sdk
2. setup your wallet
3. setup php
4. test

1. setup and install oracle stuff

mkdir /opt/oracle
mkdir /opt/oracle
cd /opt/oracle
wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basic-linux.x64-19.3.0.0.0dbru.zip
wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-sdk-linux.x64-19.3.0.0.0dbru.zip
unzip instantclient-basic-linux.x64*.zip
unzip instantclient-sdk-linux.x64-*.zip
echo /opt/oracle/instantclient_19_3 > /etc/ld.so.conf.d/oracle-instantclient
ldconfig
echo "LD_LIBRARY_PATH=/opt/oracle/instantclient_19_3:$LD_LIBRARY_PATH" >> /etc/enviroment
LD_LIBRARY_PATH=/opt/oracle/instantclient_19_3:$LD_LIBRARY_PATH


2. setup wallet
Download your wallet from the OCI database page

cd /opt/oracle/instantclient_19_3/network/admin/ 
** get your wallet, put it here
unzip Wallet_DB*.zip   
** shouldn't need this
export TNS_ADMIN=/opt/oracle/instantclient_19_3/network/admin   

3. setup php

apt-get install php-dev php-pear build-essential libaio1
pecl install oci8
**when asked use, instantclient,/opt/oracle/instantclient_19_3
echo "extension = oci8.so" >> /etc/php/7.2/cli/php.ini

4. test
use your ADMIN password or whatever creds.  see you connection names in /opt/oracle/instantclient_19_3/network/admin/tnsnames.ora 


$conn = oci_connect("ADMIN", "password", "connection name from tnsnames", null, 0);

if ($conn) {
   print "Success, connected!\n";
} else {
   $m = oci_error();
   echo $m['message'], "\n"; 
}

oci_close($conn);
  

Thanks to https://gist.github.com/hewerthomn/81eea2935051eb2500941a9309bca703

Comments

Popular posts from this blog

Baileys liquor Chocolate Chip and Cream desert

nginx decode base64 url for use with imgproxy

using t1n1wall, opnsense or pfsense on Google Compute Engine GCE