Wednesday, September 24, 2008

XAMPP with Oracle : oci.dll not found

For my quickie...
By codrai .. OTN Forum
http://forums.oracle.com/forums/thread.jspa?threadID=406036&tstart=60&start=15


How to configure Oracle, Apache and PHP.

Ingredients
XAMPP implementation of Apache and PHP
Apache version 2.2
PHP 5.1.2
Oracle 10G Base client
Windows XP
Remote Oracle 9.1 database
URL’s
Oracle 10G Base client
http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html
File Monitor
http://www.microsoft.com/technet/sysinternals/FileAndDisk/Filemon.mspx
Dependancy Walker
http://www.dependencywalker.com/
Steps
As with all things, this is easy once you know how. It is equally easy to get it wrong. I have included some information on how to debug issues.

I do not cover the install of Apache and PHP. XAMMP does a good job of this.

Start with configuring the Oracle client. Note; I had version 9 of the Oracle client on my machine. I had also read that the Oracle DLL for PHP supported versions 9 and 8 of Oracle so it took me a while to click that I needed version 10 of the client. There is a link above to version 10 of the client, this is a cut down client.

Download the client and copy the files to a suitable directory, say C:\Oracle10Client.
You need to manually configure some environment variables. I had read numerous articles with conflicting advise on this. I set the following:

TNS_ADMIN=C:\Oracle10Client\instantclient_10_2
Path=C:\Oracle10Client\instantclient_10_2;
NLS_LANG=ENGLISH_UNITED KINGDOM.WE8MSWIN1252
Enable oracle in PHP.INI

I only had to change one line, but 1st I had to make sure I had the right php.ini, XAMPP had created 3 and I had other versions from earlier installs.

My installation of XAMPP has the following file: http://localhost/xampp/phpinfo.php
This pointed me to the following location C:\Program Files\xampp\apache\bin\php.ini

I only had to change one entry, uncommenting the following line:
;extension = php_oci8.dll

That should have been enough. All I should have needed to was restart Apache and I’m away. I should have been able to go back to http://localhost/xampp/phpinfo.php and search for OCI to learn that OCI had been enabled.
Debugging options

It was not working and I probably made it worse until I solved the problems, but these are the activities I undertook.

I found the following error statement at C:\Program Files\xampp\apache\logs\error.log:

PHP Warning: PHP Startup: Unable to load dynamic library 'C:
Program Files\\xampp\\php\\ext
php_oci8.dll' - The specified procedure could not be found.\r\n in Unknown on line 0

I did the usual Google searches to find a solution.

I downloaded Dependency Walker. This is quite complicated for a novice, but it did give me a clue. I opened php_oci8.dll and it showed red on opening oci.dll and php5ts.dll. The real value was that it gives you path information for the instances of DLL’s I realised that it was calling the wrong DLL’s.

I played with paths and copied DLL’s all over the place. This made Dependency Walker happy, but not Apache.

I tested PHP directly from the command line with my little Oracle/PHP script

"C:\Program Files\xampp\php\php.exe" "C:\Program Files\xampp\htdocs\test\test.php". This worked successfully. I seen posts on the web that this helped identify other issues, such as wrong versions of DLL’s.

I was now stumped.

I then decided to use an old tool I had from a company called sysinternals (now looks like it is owned by Microsoft?) called filemon. I recorded the activity as Apache started up.

I noticed that apache was calling an earlier version of OCI.DLL. I overwrote this with the 10g version and voila.

I confirmed it was setup with the http://localhost/xampp/phpinfo.php which showed that OCI Support was enabled.

In short my main problems were due to not having a clean install base and having to ensure Apache used the correct DLL’s.

3 comments:

BenK said...

xampp windows, apache oracle, instant client.
thanks dude, this helped me he heaps.
i had cleaned oracle off my system, and just unzipped instant client but still no love.
the oci.dll i had was conflicting with the one in xampp/apache/bin/oci.dll
deleted this and it found the right one!

surfer said...

thanks for your help guys. but just wanted to update you guys on something. This is actually a follow for [@BbErSeRkK:the oci.dll i had was conflicting with the one in xampp/apache/bin/oci.dll
deleted this and it found the right one!] for me it worked the other way. I actually didnt had a oci.dll in my xammp/apache/bin/ folder. so copied the one from the oracle client i installed. now OCI appears to be showing up on my php.ini.

just wanted to keep you'll updated so you'll know. anyways thanks a lot guys, your comments help me a great way.

Gilbertus Gunawan Lie said...

Thanks for your post. It really helps me to get the painful problem. By the way, this is my input for other reader. What I've done was after uncommented the php_oci8.dll, then I renamed the oci.dll to other name in my Windows installation folder. Restart the Apache and it works! That's it!