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.