I recently had to work with Symfony and Oracle, and struggled slightly before getting things up and running. This document is the verbatim of the commands I used in order to get a stable and (rather) performant architecture, even though I would urge everyone not to use Oracle with PHP. I hope it will help others struggling with the install.
Install some system applications
I started with a freshly installed Ubuntu 9.10 Server, and directly added several packages:
# apt-get install apache2 php5 php5-cli php-apc php5-xdebug php5-memcache php5-mcrypt php5-imagick php5-gd php5-xsl subversion imagemagick unzip htop memcached
In order to check if the extensions have been well configured, type the command "php -m
" in the terminal, and they should display in the list.
Install Oracle Instant Client Libraries
Go to Oracle website, and download these two things:
- Oracle instant client basic 10.2.0.4, zip packagew
- Oracle instant client sdk 10.2.0.4, zip package
Put both of these files in /tmp
. Then (yes, I know, it's the command horror show):
cd /tmp/
unzip oracle-instantclient-basic-10.2.0.4-1.i386.zip
mv instantclient_10_2 /opt/
unzip oracle-instantclient-devel-10.2.0.4-1.i386.zip
mv instantclient_10_2/sdk /opt/instantclient_10_2/
export ORACLE_HOME=/opt/instantclient_10_2/
ln -s /opt/instantclient_10_2/libclntsh.so.10.1 /opt/instantclient_10_2//libclntsh.so
ln -s /opt/instantclient_10_2/libocci.so.10.1 /opt/instantclient_10_2//libocci.so
ln -s /opt/instantclient_10_2/ /opt/instantclient_10_2/lib
PDO, PDO_OCI and OCI8 installation
The default PECL install does not work straight out of the box. You must download and build manually the packages:
pecl download pdo PDO_OCI OCI8
tar xzvf PDO-1.0.3.tgz
tar xzvf oci8-1.3.5.tgz
tar xzvf PDO_OCI-1.0.tgz
cd PDO-1.0.3
phpize
./configure
make
sudo make install
cd ../oci8-1.3.5
phpize
./configure --with-oci8=instantclient,/opt/instantclient_10_2/
make
sudo make install
cd ../PDO_OCI-1.0
cp /opt/instantclient_10_2/sdk/include/*.h .
phpize
./configure
make
sudo make install
At that point, the libraries have been built but are not used by PHP. In this extent, you must add it at the bottom of php.ini files, /etc/php5/cli/php.ini
and /etc/php5/apache2/php.ini
:
extension = pdo.so
extension = pdo_oci.so
extension = oci8.so
As a sidenote, if you want to install PDO_OCI or OCI8 on Mac OSX, you'll have to declare a DYLD_LIBRARY_PATH
shell variable, with the path to the Orale instant client install. Both OCI8 and PDO_OCI require extra configuration directives:
./configure --with-pdo-oci=instantclient,/path/to/instantclient,10.2.0.4
Conclusion
You should have been able to connect to a Oracle server and use it from within PHP. However I have a better advice: don't use Oracle. It has not been thought to work with PHP, nor has PHP been thought to work with it. Stick to a "classical" platform, or at least try more modern solutions. And that will be fine.
- written on: 2009-11-03
- tags: