Oracle 10g XE + PHP on Debian

March 20th, 2010 @ Laurens

3


I reinstalled my ye-old server today. It’s a old Celeron 700 with a whopping 512MB RAM! Even on this machine it’s possible to run the World’s Best Database: Oracle. I want to run this database (instead of “the usual” MySQL [also from Oracle nowadays :-) ] because I need PL/SQL (and PL/SQL rocks).

If you want to run this database on an Intel-based Debian machine, and also want to use PHP with Oracle, just do this (I assume you’ll already have Apache + PHP):

  1. Get Oracle 10g XE (it’s free).
  2. Use apt-get to install the packages gcc, make, libaio1, php-dev, php-pear (… if I’ve forgotten one, please apt-get it on-the-fly :-) ).
  3. Install the database using dpkg -i <oracle-xe DEB file>
  4. As root, run /etc/init.d/oracle-xe configure
  5. Install the oci8 module for PHP: pecl install oci8
    Fill in the ORACLE_HOME. (see point below).
  6. Make sure you set the following exports (system-wide):
    export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
    export ORACLE_SID=XE
    export LC_ALL=C
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
    These environment variables must be known to Apache. Don’t have a nice solution for this yet (I’ve hacked it in a Apache startup script). But you can probably put this in the envvars script in Apache’s bin directory?
  7. Add extension=oci8.so to the php.ini. Don’t forget to set the extension_dir. If it’s already set, then you should put the oci8.so in that directory. By default pecl will put it somewhere in /usr/lib/php5
  8. Restart apache and you’re done!

For more info on oci8 installation: check the php.net website.

This is your new toolset in PHP. Happy coding. For writing PL/SQL on your new database, SQL Developer is a great IDE to use.