<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechKnack &#187; databases</title>
	<atom:link href="http://techknack.net/category/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://techknack.net</link>
	<description>The rantings of a techie</description>
	<lastBuildDate>Thu, 24 Dec 2009 19:53:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing OCI8 for PHP</title>
		<link>http://techknack.net/installing-oci8-for-php/</link>
		<comments>http://techknack.net/installing-oci8-for-php/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 04:49:31 +0000</pubDate>
		<dc:creator>eternicode</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://techknack.net/?p=198</guid>
		<description><![CDATA[I recently had a project that required me to connect to a remote Oracle 10g database from my local server using a PHP-based client, the problem being that the default PHP install has no libraries for working with Oracle.  Fortunately, Oracle has released binaries for their OCI, or Oracle Call Interface, for Linux systems.
Once [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a project that required me to connect to a remote Oracle 10g database from my local server using a PHP-based client, the problem being that the default PHP install has no libraries for working with Oracle.  Fortunately, Oracle has released binaries for their OCI, or Oracle Call Interface, for Linux systems.</p>
<p>Once you have these binaries, however, you have to figure out how to integrate them with your system and with PHP.  The fairly concise and complete guide that I came across was <a href="http://en.opensuse.org/Howto_build_oci8_extension_module_for_php">Howto build OCI8 extension module for php</a>.  The catch?  It&#8217;s on the OpenSUSE wiki, and I use Ubuntu server.  Fortunately, the instructions worked very well, regardless of distro differences.  I did, however, discover some things that would make the install process easier, and so I offer up these steps to any pioneering PHP/Oracle developers.  It may be useful to &#8220;sudo su&#8221; for this, as you will otherwise need a lot of sudoing commands:</p>
<ol>
<li>
Download the <a href="http://www.oracle.com/technology/software/tech/oci/instantclient/index.html">Oracle InstantClient</a> binary zips (I used the &#8220;Linux x86&#8243; distribution).  You will need the Basic and SDK packages.  Also, you will need <a href="http://www.bugmenot.com/">an Oracle.com account</a> in order to download the files.
</li>
<li>
Once you&#8217;ve downloaded the files, mkdir (with root privileges) the /opt/oracle directory and unzip the zip files to that directory, as per the OpenSUSE instructions.  You will end up with one directory called &#8220;instantclient_XX_X&#8221;, where &#8220;XX_X &#8220;is the instantclient version number.
</li>
<li>
Inside the instantclient directory, symlink libclntsh.so:</p>
<pre class="brush: bash;">
$ ln -s libclntsh.so.11.1 libclntsh.so
</pre>
<p>I&#8217;m not sure this is necessary, as after I installed OCI8, that file is no longer a symlink.</li>
<li>Install the php5-dev and php-pear packages.</li>
<li>At a command line, run &#8220;pecl search oci&#8221;.  This should return at least one package with a description that reads &#8220;Extension for Oracle Database&#8221;.  Note the package name, and then run &#8220;pecl install {package-name}&#8221;, where {package-name} is the name of the package from your search.
</li>
<li>
As pecl runs about, making sure everything is ready for the oci package, it may notice that you have no ORACLE_HOME environment variable set, and will prompt you for the information:</p>
<pre class="brush: bash;">
root@computer:/opt/oracle# sudo pecl install oci8
downloading oci8-1.3.4.tgz ...
Starting to download oci8-1.3.4.tgz (134,240 bytes)
.............................done: 134,240 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
 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

1-1, 'all', 'abort', or Enter to continue:
</pre>
<p>This is the tricky part that no one seems to explain very well (and the text of the prompt doesn&#8217;t help at all): that second &#8220;1&#8243; after the &#8220;1-&#8221; is an option.  If you simply enter the path to your instantclient files, pecl will switch to autodetect mode.  However, if you enter &#8220;1&#8243; here, then &#8220;instantclient,/opt/oracle/instantclient_11_1&#8243; at the next prompt (and hit enter at the prompt after that, I don&#8217;t know why it shows up), it should work fine.</p>
<pre class="brush: bash;">
1-1, 'all', 'abort', or Enter to continue: 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] : instantclient,/opt/oracle/instantclient_11_1
 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 : instantclient,/opt/oracle/instantclient_11_1

1-1, 'all', 'abort', or Enter to continue: [Enter]
building in /var/tmp/pear-build-root/oci8-1.3.4
running: /tmp/pear/cache/oci8-1.3.4/configure --with-oci8=instantclient,/opt/oracle/instantclient_11_1
checking for ......
</pre>
</li>
<li>
Contrary to the OpenSUSE article, I found no need to set an LD_LIBRARY_PATH variable &#8212; the functions worked just fine without it.
</li>
<li>
Edit the php.ini files as necessary (add the line &#8220;extension=oci8.so&#8221;)
</li>
<li>
I did get an error concerning libaio.so.1:</p>
<pre class="brush: bash;">
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/oci8.so' - libaio.so.1: cannot open shared object file: No such file or directory in Unknown on line 0
</pre>
<p>Installing packages libaio1 and libaio-dev solved this problem, though I&#8217;m not so sure libaio-dev is necessary.
</li>
<li>
Assuming everything went well, you should be able to use the <a href="http://us2.php.net/manual/en/function.oci-connect.php">PHP OCI8 functions</a> without anything other than &#8220;insufficient arguments&#8221; complaints <img src='http://techknack.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .  And don&#8217;t forget to <a href="http://us2.php.net/manual/en/function.oci-commit.php">oci_commit()</a>!
</li>
</ol>
<p>If I missed anything or am unclear about something, feel free to ask questions.  I&#8217;ve used these steps to successfully set up OCI8 on two separate computers running Kubuntu Hardy and Ubuntu Hardy Server.  OpenSUSE folks should note that the php-pear package may be named php5-pear instead; I don&#8217;t know about the libaio packages.</p>
<img src="http://techknack.net/?ak_action=api_record_view&id=198&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://techknack.net/installing-oci8-for-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
