PHP5 with Oracle client on FreeBSD tutorial
Updated 2007-01-28. I have updated this tutorial to simplify the process and make it more clear.
This post is intented to help those trying to install PHP with Oracle support on FreeBSD. I’ll just note that this setup was tested and implemented in FreeBSD 6.2-STABLE. I also assume that your ports location is /usr/ports.
1. Install necessary FreeBSD ports
- Oracle instant client: /usr/ports/databases/linux-oracle-instantclient-basic/
You’ll need to download a Linux version of instant client from http://www.oracle.com/technology/tech/oci/instantclient/index.html and put it in /usr/ports/distfiles/oracle. The exact version will depend on the freshness of your port revision. At the moment of writing it is “instantclient-basic-linux32-10.2.0.2-20060331.zip”. - Oracle instant client SDK: /usr/ports/databases/linux-oracle-instantclient-sdk/
Another file for download from Oracle (location and destination are the same like in step 1). File name at the moment of writing is “instantclient-sdk-linux32-10.2.0.2-20060331.zip”. - Oracle8-client: /usr/ports/databases/oracle8-client/
Unofficial port of Linux version Oracle client. After doing “make install” go to /usr/local/oracle8-client/freebsd. Execute redefine-syms.sh, then – make, make patch and make install. If make fails with redefinition of gethostbyname_r function error, open oci8stub.c for editing and delete the declaration of this function in this file. Now it should compile correctly. After doing make install, symlink /lib/liboci8stub.a to /usr/local/oracle8-client/lib.
2. Environment setup
- (optional) Set linker options. If you’re using bash, type: export LDFLAGS=”-lcompat -lpthread”
- Set ORACLE_HOME location. If you’re using bash, type: export ORACLE_HOME=”/usr/local/oracle8-client”
3. Install PHP5
- Install PHP5 base from /usr/ports/lang/php5 (make && make install)
- Install PHP5 extensions from /opt/ports/lang/php5-extensions (make – for typical ncurses menu – simple but very convenient) NOTE: you won’t find OCI8 or other database extensions here – they are located in the other location
- Install PHP5-OCI8 extension from /usr/ports/databases/php5-oci8 (you’ll find all other available PHP5 database extensions in /usr/ports/databases)
4. Tips
- It is mandatory that ORACLE_HOME environment variable is set to /usr/local/oracle8-client during startup of Apache (or any other web server of your choice).
- If you want to use tnsnames.ora then put it into /usr/local/oracle8-client/network/admin. Adjust necessary settings in sqlnet.ora as well.
- In some cases setting TNS_ADMIN environment variable to /usr/local/oracle8-client/network/admin is necessary.
Feel free to comment if you encounter any problems with this tutorial.
Ganbat said,
December 12, 2006 @ 04:57
I have some error.
make install clean
===> Vulnerability check disabled, database not found
===> Extracting for linux-oracle-instantclient-basic-10.2.0.2.20060331
=> No MD5 checksum recorded for oracle/instantclient-basic-linux32-10.2.0.2-20060331.zip.
=> No SHA256 checksum recorded for oracle/instantclient-basic-linux32-10.2.0.2-20060331.zip.
=> No suitable checksum found for oracle/instantclient-basic-linux32-10.2.0.2-20060331.zip.
*** Error code 1
Stop in /usr/ports/databases/linux-oracle-instantclient-basic.
what should I do
Justinas Balčiūnas said,
January 28, 2007 @ 19:48
you should update your ports tree from CVS. that should help
Jerry said,
February 6, 2007 @ 17:10
What was your linux_base? (my: fc49)
changes: instantclient 1.2.0.3 (1.2.0.2 isn’t downloadable from oracle anymore) (patched makefiles and distfiles to reflect change in names, checksums, sizes)
# php
Jerry said,
February 6, 2007 @ 17:11
What was your linux_base? (my: fc49)
changes: instantclient 1.2.0.3 (1.2.0.2 isn’t downloadable from oracle anymore) (patched makefiles and distfiles to reflect change in names, checksums, sizes)
# php < oracle.php
Segmentation fault: 11 (core dumped)
Do you have any idea?
(sorry for doublepost < was not properly filtered)
Justinas Balčiūnas said,
February 6, 2007 @ 22:24
actually there shouldn’t be any difference whether you use oracle instant client version 1.2.0.3 or 1.2.0.2. so i suppose your problem is not here.
environment variables are very important for the OCI extentension to work properly. if you’ve installed oracle-client8 ( from /usr/ports/databases/oracle8-client to, presumably, /usr/local/oracle8-client ) then you should set your ORACLE_HOME environment variable to /usr/local/oracle8-client.
regarding linux_base version. looking at the current port tree, linux_base-fc4 is the best option. personally i’d choose this one. i don’t remember the exact port name i installed as linux_compat but my redhat-release file (from /usr/compat/linux/etc) says i’m using Red Hat Linux release 8.0.
valdiic said,
February 8, 2007 @ 12:08
Why do you install Oracle instant client linux version? IMHO it is not used at all if you use oracle8-client port which is native.
I tried to connect oracle 10g server from php5-5.2.0 using oracle8-client-0.1.1_1 and php5-oci8-5.2.0 on FreeBSD 6.2-RELEASE box. Everything works more or less ok except that php encouters segmentation fault upon exit. Probably there is a bug in oracle8-client.
Actually I would like to try linux instantclient with php5-oci8 extension. Do you know any way how I could do it?
nacho said,
February 9, 2007 @ 01:55
Thanks for the installation guide – I have the oracle client working ok through apache 2.2 and php5-5.2.0 on 6.2-RELEASE. However, when I run php CLI I get a segmentation fault/core dump. Has anyone else encountered this issue?
Justinas Balčiūnas said,
February 9, 2007 @ 08:29
I think Jerry (post above) is experiencing the same problem. I tested my scripts (including alter session, variable binding, stored procedures, cursors, etc) from command line and I’m not getting any segfaults.
Pahaps you could post a piece of your code to find if you’re using any specific functions that are causing a segfault.
valdiic said,
February 9, 2007 @ 11:02
Segfault occurs upon exiting php cli process.
After executing any of these functions (ociplogon, ocilogon) I get the segfault. There is no difference if there were any errors from oracle or not.
tommy said,
February 25, 2007 @ 12:50
try disabling the sessions.so extension. for some reasons, the session extensions causes a segfault in php-cli for me. the script completes fine, no errors, but sigfault(11) every time.
Jon said,
February 28, 2007 @ 22:18
We have been trying to use the Oracle8 client with PHP5 on FreeBSD 6 but have experienced crashes when the PHP CLI terminates. Disabling sessions in PHP5 didn’t help. We do not currently have linux compatiblity enabled.
Does the Oracle8 client only work on FreeBSD if linux compatiblity is enabled?
Dan said,
March 5, 2007 @ 13:45
Hello all,
I get the seg fault as well, can somebody with a working setup share his list of php5-extensions?
I believe that some extensions are the cause of this.
Thanks,
Dan
Justinas Balčiūnas said,
March 5, 2007 @ 14:36
I agree with Dan and other about the extensions. So here’s the list of extensions that are currently enabled in my system (PHP 5.1.6) and that are not causing segfaults (as there are none in my logs):
curl, date, dom, ftp, gettext, iconv, libxml, mbstring, mysql, mysqli, oci8 (obviously
), openssl, pcre, posix, Reflection, session, SimpleXML, sockets, SPL, tokenizer, xml, xmlreader, xmlwriter, xsl, zip and zlib.
Zend Optimizer 3.0.1 is enabled as well. I’ve also set ORACLE_HOME (/usr/local/oracle8-client ) and NLS_LANG (LITHUANIAN_LITHUANIA.BLT8MSWIN1257 but that’s for Lithuania. Probably you’ll need something else. Check out this one: http://www.oracle.com/technology/tech/globalization/htdocs/nls_lang%20faq.htm) variables in my Apache/2.2.3 environment.
Dan said,
March 5, 2007 @ 17:22
Hello Justinas Balčiūnas,
Thank you for your tutorial and for your quick answer.
Can you tell me from where did you install the following extensions: date, libxml and Reflection, I don’t find them in ports.
Thank you,
Dan
Justinas Balčiūnas said,
March 5, 2007 @ 17:25
Those are installed by default in PHP5 so there’s no need (or way) to install them separately.
Dan said,
March 6, 2007 @ 16:52
Hello Justinas Balčiūnas,
Thank you for your answers.
I have installed all extensions that you have, but I steel have the seg fault.
Could you provide a list with versions of your installed php and oracle packages, like the one pkg_info is showing?
I’m trying to narrow this.
Thank you,
Dan
Dan said,
March 8, 2007 @ 13:05
Hello,
.
I have downgraded my ports 16 oct. 2006, but I get that seg fault too
I think that something is wrong with my native client.
Can you tell us if oci02 test from /usr/local/oracle8-client/freebsd/demo runs on your system.
I get a failure here, and if it runs on your system can you tell us what ldd oci02 tell on your system.
On my system i get:
oci02:
libm.so.4 => /lib/libm.so.4 (0×484d9000)
libpthread.so.2 => /lib/libpthread.so.2 (0×484f2000)
libc.so.6 => /lib/libc.so.6 (0×48517000)
Maybe it’s a lib problem.
Thanks,
Dan
Justinas Balčiūnas said,
March 8, 2007 @ 22:07
Yes, the problem really is in the libs and your output shows that. The problem itself lies within libpthread and oracle client uses it as the client binaries are compiled for Linux therefore Linux threading libraries should be used as well.
To solve this problem your rc.conf should include this line:
linux_enable=”YES”
After you do this – reboot your system for this directive to take effect.
If this does not solve segfaults problem then we’ll try to play with LD_LIBRARY_PATH environment variable
but I hope this won’t be necessary
Dan said,
March 9, 2007 @ 09:17
Hello Justinas Balčiūnas,
I have linux_enabled, and I’m sure that this is working properly, because I have java installed on that box and it’s working fine.
Can you provide your ldd output, so that i could figure what to use on LD_LIBRARY_PATH?
Thank you,
Dan
Justinas Balčiūnas said,
March 9, 2007 @ 13:40
Another thing to check before messing with LD_LIBRARY_PATH.
Do you set environment variables ORACLE_HOME and NLS_LANG before executing your php script in cli? If not, set them with appropriate values using setenv or export.
I just checked my system setup and found out that scripts fail if these are not set.
Dan said,
March 9, 2007 @ 16:31
Hello,
I have these variables set and TNS_ADMIN too, but i get that seg fault.
If you say that your oci02 it’s linked differently, then it’s something wrong with my ports or system. But I can’t figure what because i have, like I said, downgraded my ports to your ports versions, except for linux-oracle packages because i don’t find them on oracle’s site, could you provide them for me, please?
And also list here what is your ldd output on oci02?
Thank you,
Dan
Gordon said,
March 11, 2007 @ 03:12
Hey,
I’m also having problems with a segmentation fault upon _exiting_ a script that invoked the Oracle extension for PHP. For clarification, everything in the script works perfectly up until the script exits, at which point a segfault occurs, so the scripts _do not_ fail, they merely segfault as they’re exiting. I’m wondering about the benefits of having the Oracle Instant Client installed — ports does not build PHP’s oci8 extension against anything except the unofficial FreeBSD port libraries (oracle8-client), and the instant client libraries are not mentioned anywhere else in your tutorial except to install them at the beginning. The backtrace from a crash looks like this (no debugging symbols, sorry):
(gdb) bt
#0 0×2910427c in ?? ()
#1 0×2854f32b in __cxa_finalize () from /lib/libc.so.6
#2 0×2854ef66 in exit () from /lib/libc.so.6
#3 0×081a3393 in main ()
so that’s not very helpful. If it had something that looked useful I’d recompile with debugging symbols, but this backtrace doesn’t look to be helpful.
Is there a reason that we need the instant client?
Dan said,
March 12, 2007 @ 10:29
Hello Gordon,
Can you tell me the versions of your installed packages, because I receive a seg fault at when I invoke OCIlogin, not upon exit like you, maybe I could figure what is wrong with my system.
Also please tell me if you have followed the exact procedure described in this tutorial, or you have done something more.
Thank you,
Dan
Gordon said,
March 13, 2007 @ 00:07
Hey Dan,
I’m running FreeBSD 6.2-RELEASE-p1.
oci8 extension: 1.2.3 (ports has it as 5.1.2_3)
oracle8-client: 0.1.1_1
Currently, I don’t have the instant client or SDK installed. When I originally tried setting this up, I followed the guide. I determined, however, that the oci8 extension that was segfaulting was not linked with the instant client. That’s what prompted my previous question: I am curious about the relationship between the PHP oci extension and the instant client, as the oracle8-client is starting to get pretty old and I’m wondering if these segfaults are a result of API/ABI incompatibilities. If that is the case, I will have to find a way to force the oci8 extension to link with the instant client. Since we’re running FreeBSD, the instant client requires Linux binary compatibility mode enabled as well, something I will do again if I determine that I do indeed need the instant client, but I prefer to keep the complexity on production servers at a minimum.
Justinas seems pretty knowledgeable, and I was hoping to get a little bit of detail on these library relationships.
valdiic said,
March 13, 2007 @ 09:36
I tried to compile php5 with instantclient. I almost did it but ran in problems with shared libraries. I suppose that it is possible to run php with instantclient. It just asks for some more time messing around shared libraries.
Conrad said,
April 6, 2007 @ 18:46
I am having the EXACT same problem as Gordon’s post on March 11, 2007.
BSD 6.+, PHP 5.+, OCI8 1.2+. Oracle8-client. Environment variables all set, inserts, updates, selects, deletes all work fine. Same setup, and same segmentation fault on exit!
If anyone has resolved this, please post.
Thanks.
Bambang C Prasetya said,
May 25, 2007 @ 06:35
I try install linux-oracle-instantclient-basic from port,
but i cant’s find file instantclient-basic-linux32-10.2.0.2-20060331.zip.
Where i can download that file???
nocon said,
August 17, 2007 @ 22:16
This is a bit of a Hack. Quick Oracle perl wrapper for PHP
http://nocon.darkflame.net/notes/php-perl-Oracle.txt
Gordon said,
September 13, 2007 @ 01:05
Conrad and others,
I’ve solved the problem I was wrestling with, and I’ve written up my solution at http://canonical.wordpress.com/2007/09/12/freebsd-php-oci8-segfault-fix
I hope this helps somebody, and would be happy to hear from people if it does as well as ways the fix could be improved.
Gordon
Dmitry said,
November 15, 2007 @ 14:09
very good article… but i have problem.
dmz-uln01# make
===> Vulnerability check disabled, database not found
===> Extracting for oracle8-client-0.2.0
=> MD5 Checksum OK for oracle8-client-0.2.0.tar.bz2.
=> SHA256 Checksum OK for oracle8-client-0.2.0.tar.bz2.
===> Patching for oracle8-client-0.2.0
===> Configuring for oracle8-client-0.2.0
===> Building for oracle8-client-0.2.0
cc -O2 -fno-strict-aliasing -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -c oci8stub.c
cc -O2 -fno-strict-aliasing -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -c ecvt.c
ecvt.c:98: warning: no previous prototype for ‘ecvt’
ecvt.c:104: warning: no previous prototype for ‘fcvt’
*** Error code 1
Stop in /usr/ports/databases/oracle8-client/work/oracle8-client/freebsd.
*** Error code 1
Stop in /usr/ports/databases/oracle8-client.
Выход 1
Any ideas?
Justinas Balčiūnas said,
November 15, 2007 @ 15:32
The problem is clearly with IEEE floating point formatting routines for FreeBSD (cvt) from GNU libc.
I am currently updating my ports tree from CVS for 6-STABLE branch and will see where’s the problem exactly. By the way, Dmitry, which port branch are you using?
Justinas Balčiūnas said,
November 15, 2007 @ 17:09
I’ve taken a look into oracle8-client-0.2.0 and found out that it:
1. Has slight problems with freebsd/ecvt.c and global stdlib.h (to compile ecvt.c you need to uncomment cvt declarations in stdlib.h);
2. Has BIG problems with strtod.c file due to conflicts with global math.h it includes (declaration of j1 on line 1915), and later on, with mlo pointer in __dtoa function.
Therefore I believe this port revision is broken. I suppose that a good option would be to use a previous version (0.1.1).
Dmitry said,
November 16, 2007 @ 09:26
Hmm… and how to back to ports version where oracle8-client will be 0.1.1?
Justinas Balčiūnas said,
November 16, 2007 @ 09:42
Create a new sup file for updating like this one:
*default tag=.
*default host=cvsup.fi.freebsd.org
*default prefix=/usr
*default base=/usr/local/cvsup
*default release=cvs delete use-rel-suffix
*default date=2006.01.01.01.01.01
ports-databases
and then run your ports update from cvs using this sup file. You would obviously want to revert to your current sup file after you’re finished with oracle8-client
freebsd software said,
November 24, 2007 @ 02:46
run the portupdate, it should work.
alberto said,
November 30, 2007 @ 00:57
Has anyone have the two zip files (basic and SDK) for version 10.1.0.3 ? I only can get 10.1.0.5 from Oracle…
Thanks!!
Justinas Balčiūnas said,
November 30, 2007 @ 21:37
i see no reason why would you want the older version?
Westin Shafer said,
January 23, 2008 @ 21:28
Thanks for the how-to. Oracle is up and running.
However, we are also experiencing the segfault on freebsd 6.2_RELEASE. This happens only on exit. This is also not related to other extensions, as I was able to test OCI8 first before installing the other modules.
Other problems include oci_pconnect will leave connections open indefinitely and oci_close has no effect on these connections.
The fix posted earlier seems to clear up the problem with the segfault, but I wonder how good the fix truly is. Anyone have any issues once the patch is installed, things like having to restart apache, server, ect?
As a side question,
Has anyone been able to compile the pecl oci8 client instead?
Tom Weber said,
February 28, 2008 @ 18:21
Today I tried to upgrade my 6.2-STABLE to 7.0-RELEASE. I’ve used Oracle together with Perl and DBD::Oracle, wich worked thanks to this tutorial.
After upgrading the libs were broken. SQLPlus was working as expected, but in Perl I got several errors.
I had to rebuild Perl with all modules wich have something to do with Oracle, as well as all Oracle packages. Now it works perfectly again.
So Oracle client under FreeBSD 7.0-RELEASE is reported as success!
Justinas Balčiūnas said,
February 29, 2008 @ 13:30
Thanks for the feedback Tom Weber!
Snaut said,
March 6, 2008 @ 11:46
Hi! With Apache 2.2.8+PHP5.2.5+oracle-client 1.2.0
i have:
[Thu Mar 06 12:34:52 2008] [notice] child pid 1587 exit signal Bus error (10)
[Thu Mar 06 12:43:07 2008] [notice] child pid 2205 exit signal Bus error (10)
On the php5.2.3+oracle-client 1.1.1 works fine… any ideas?
Josh said,
April 23, 2008 @ 21:23
Thanks for the write-up. I have Oracle support apparently working in PHP5 according to phpinfo(), but I have yet to actually do anything with it.
Josh said,
May 9, 2008 @ 04:38
Actually…Does setting ORACLE_HOME on the command line have any effect? I believe that building a port wipes out the environment vars so you can’t “pollute” the port build.
Josh said,
May 9, 2008 @ 04:40
If you do a phpinfo() after getting the OCI module built you’ll see that there was no compile-time ORACLE_HOME value set. The module still works fine for me as long as I have ORACLE_HOME set in httpd.conf and in my PHP scripts before I use any OCI functions.
noisex said,
May 13, 2008 @ 19:12
Hallo!
I have the same problem as many of you described:
FreeBSD 7.0, PHP 5.2.6, PHP5-OCI8 1.2.5, Oracle 8 client 0.2.0_1. (All up2date). So every time when PHP-CLI or PHP-CGI script exits from comandline PHP die with seg.fault 11 (core dumped). I tried to recompile with this one patch http://canonical.wordpress.com/2007/09/12/freebsd-php-oci8-segfault-fix/ but on PHP5.2.6 this didn’t work for me. I hate this entries in /var/log/messages that my php died every time when script exits (i have a lot of scripts which run from CLI in crontab).
GDB debugger also nothing more than error didn’t tell me:
Program terminated with signal 11, Segmentation fault.
#0 0×88f18acc in ?? ()
So now many scripts i rewrite in perl which using p5-bdb-oracle with no problems or crashes.
Has anybody is submited this one to PHP or FREEBSD mailinglist/bug report?
Westin Shafer said,
July 9, 2008 @ 21:13
“Has anybody is submited this one to PHP or FREEBSD mailinglist/bug report?”
I did and they only came back with “This is a problem with the pspell extension.”
While this did cleare up the segfault I was getting in httpd-error.log file it did not clear up the CLI.
I also installed the PDO_OCI driver as well, and it appears that the segfault happends with it too.