DB2 10.5 for Linux, UNIX, and Windows

Setting up the PHP environment for IBM Data Server products on Linux or UNIX

Before you can connect to an IBM® database server and run SQL statements, you must set up the PHP environment.

Before you begin

You must have the following required software installed on your system:

Procedure

To install the ibm_db2 and pdo_ibm php extensions:

  1. Using the export command, set the environment variable IBM_DB_HOME.
    $export IBM_DB_HOME=DB2HOME
    The DB2HOME is the directory where the IBM Data Server product is installed. For example:
    $ export IBM_DB_HOME=/home/db2inst1/sqllib
  2. Using one of the following three methods, install the ibm_db and pdo_ibm extensions.
    • Use the pecl install command included in the PHP Extension Community Library (PECL).
      • To install the ibm_db2 extension:
        $ pecl install ibm_db2
      • To install the pdo_ibm extension:
        $ pecl install pdo_ibm
    • Use the commands included in the source code:
      1. Extract the source archive.
      2. Run the following commands from the extracted directory:
        $ phpize --clean
        $ phpize
        $ ./configure
        $ make
        $ make install
      3. If you are installing the pdo_ibm extension, you must run the following configure command:
        $./configure --with-PDO_IBM=DB2HOME
        The DB2HOME variable is the directory where the IBM Data Server product is installed.
    • Use the compiled extensions included with the IBM Data Server products:
      1. You must determine whether your PHP environment is threadsafe or not threadsafe by issuing the following command:
        $ php -info| grep "Thread Safe"
      2. The IBM data server client and IBM Data Server Driver Package software are shipped with two types of PHP drivers:
        • Threadsafe: ibm_db2_XX_ts.so and pdo_ibm_XX_ts.so
        • Not threadsafe: ibm_db2_XX_nts.so and pdo_ibm_XX_nts.so
        Using the cp command, copy the appropriate PHP driver share library files to the installed PHP extension directory as ibm_db2.so and pdo_ibm.so files.
        For a 32-bit PHP driver:
        $ cp DB2HOME/php/php32/ibm_db2_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/ibm_db2.so
        $ cp DB2HOME/php/php32/pdo_ibm_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/pdo_ibm.so
        For a 64-bit PHP driver:
        $ cp DB2HOME/php/php64/ibm_db2_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/ibm_db2.so
        $ cp DB2HOME/php/php64/pdo_ibm_XX_[ts/nts].so <local_php_directory>/php/lib/php/extensions/pdo_ibm.so
        The DB2HOME variable is the directory where the IBM Data Server product is installed.
  3. Open the php.ini file in an editor of your choice. Edit the extension entry in the php.ini file in the <local_php_directory>/php/lib directory to reference the PHP driver:
    extension=pdo.so
    extension=ibm_db2.so
    extension=pdo_ibm.so
  4. Ensure that the PHP driver can access the libdb2.so CLI driver file by setting the LD_LIBRARY_PATH variable for Linux and UNIX operating systems other than the AIX operating system. For AIX operating system, you must set LIBPATH variable.
    • For a 32-bit Linux and UNIX operating systems other than the AIX operating system, use the export command to set the IBM_DB_HOME/lib32 directory to the LD_LIBRARY_PATH variable.
      export LD_LIBRARY_PATH=DB2HOME/lib32
    • For a 32-bit AIX operating system, use the export command to set the IBM_DB_HOME/lib32 directory to the: LIBPATH variable.
      export LIBPATH=DB2HOME/lib32
    • For a 64-bit Linux and UNIX operating systems other than the AIX operating system, use the export command to set the LD_LIBRARY_PATH variable to the IBM_DB_HOME/lib64 directory.
      export LD_LIBRARY_PATH=DB2HOME/lib64
    • For a 64-bit AIX operating system, use the export command to set the LD_LIBRARY_PATH variable to the IBM_DB_HOME/lib64 directory.
      export LIBPATH=DB2HOME/lib64
  5. Optional: If the PHP application that is connecting to an IBM database server is running in the HTTP server environment:
    1. Add the LD_LIBRARY_PATH variable in the httpd.conf file. For a 32-bit architecture, set LD_LIBRARY_PATH to the DB2HOME\lib32 directory. For a 64-bit architecture set LD_LIBRARY_PATH to the DB2HOME\lib64 directory.
    2. Restart the HTTP server so the new configuration settings take effect.