How to IBM DB2 with PHP on Linux

In the past I wrote an article how to connect to a IBM DB2 database with PHP on Windows. Now i need to connect from a Red Hat Enterprise Linux to the DB2 database. I have searched the internet for good tutorials. I have found a few, but these aren’t so good.
So I will describe here how to install PHP 5.2.1 with IBM DB2 support on an Apache 2.0.59.

First download the packages:

Copy the Packages to

/usr/local/src/lamp

and unpack it as root. To unpack both packages at the same time write this to your console:

for i in `ls *.gz`; do tar zxf $i; done;

In the next step will Apache be configured and compiled.

  1. Change the directory to the unpacked Apache directory:
    cd /usr/local/src/lamp/httpd-2.0.59
  2. Start the configure script
    ./configure --prefix=/usr/local/httpd \
    --enable-modules=all \
    --enable-so
  3. To compile Apache type
    make

    to your command line

  4. Install Apache with
    make install

To start Apache at boottime you will copy the startscript and create links to the runlevel 3.
Do this on your command line:

  1. cp /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/httpd
  2. cd /etc/rc.d/rc3.d
  3. ln -s ../init.d/httpd S20httpd
  4. ln -s ../init.d/httpd K20httpd

Now set user and group of

/usr/local/httpd/htdocs

to nobody

chown -R nobody:nobody /usr/local/httpd/htdocs/

Now compile and install PHP 5.2.1. I write the naked comand line instructions

  1. cd /usr/local/src/lamp/php-5.2.1/
  2. ./configure --with-apxs2=/usr/local/httpd/bin/apxs \
    --with-zlib-dir=/usr/lib \
    --enable-versioning \
    --enable-track-vars=yes \
    --enable-url-includes \
    --enable-sysvshm=yes \
    --enable-sysvsem=yes \
    --enable-ftp \
    --enable-calendar \
    --with-config-file-path=/etc \
    --with-ibm-db2=/home/db2inst1/sqllib
  3. Now you have to login as your database user like
    db2inst1
  4. cd /usr/local/src/lamp/php-5.2.1/
  5. make
  6. Logout and login as root
  7. cd /usr/local/src/lamp/php-5.2.1/
  8. make install
  9. cp /usr/local/sr/lamp/php-5.2.1/php.ini-dist /etc/php.ini

At the last step you have to tell apache which are php files. Add in

/usr/local/httpd/conf/httpd.conf

these two lines: ATTENTION: Only root can edit httpd.conf!

AddType application/x-httpd-php php
AddType application/x-httpd-php-source phps

Serch in the

httpd.conf

for

DirectoryIndex index.html

and replace it with

DirectoryIndex index.html index.php

Now you can start your Apache server with PHP and DB2 support with this command

/etc/init.d/httpd start

Resources:

Post Questions as a comment.

One Response to “How to IBM DB2 with PHP on Linux”

  1. [...] this post I wrote how to install Apache and PHP. I installed PEAR on this testerver too. My document [...]