Configuring PHP 5 with IBM HTTP Server, WebSphere Application Server, and DB2 UDB

02 February 2005 »

These notes will show you how to enable an existing IHS, WAS, and DB2 installation with PHP 5. PHP will be configured to support a connection to IBM DB2, and optionally, MySQL. If you don’t have MySQL installed, those specific instructions can safely be ignored. The assumption is that you have already installed and configured IHS, WAS, DB2 and MySQL for your environment. This walk-through was tested on and assumes the following software products and versions:

  • SUSE Linux Professional 9.2 on x86
  • IBM HTTP Server 1.3.28 installed at /opt/IBMHttpServer
  • WebSphere Application Server 5.1.1 [Base] installed at /opt/WebSphere/AppServer
  • DB2 UDB Enterprise Server Edition V8.2 for Linux installed at /opt/IBM/db2/V8.1 [sic]
  • MySQL 4.1.9 installed at /opt/local/mysql

WARNING: These instructions are only intended to help you set up an all-in-one LAMP and J2EE development server, do not use them on a production server installation!

DISCLAIMER: Though I work for IBM, the instructions on this site solely reflect my personal experience configuring IBM software and do not necessarily represent the views, positions, strategies or opinions of IBM, IBM management, or IBM support.

UPDATE: 24 March 2005. IBM developerWorks released an article titled “Hosting PHP applications on the IBM HTTP Server” that provides an alternative to these instructions if you are only interested in adding PHP support to IHS.

UPDATE: 12 May 2005. An article I wrote for IBM developerWorks went live with the May issue of the IBM WebSphere Developer Technical Journal. It was based on these instructions. “Pair J2EE with PHP to implement a common Web application infrastructure.”

UPDATE: 26 February 2006. I am working on an IBM Redbook for using PHP with IBM database servers. We are documenting the currently recommended way to connect to DB2 from PHP. The Unified ODBC method described below is deprecated, but will work. Please look into ibm_db2 instead. The book with more detailed steps should be out in May.

UPDATE: 14 July 2006. I’ve posted a comment covering the alternate ways of adding PHP support to a WebSphere environment. You will also find more detailed instructions on adding PHP support to IBM HTTP Server in Chapter 4 of Developing PHP Applications for IBM Data Servers.

Preparing for installation

  1. Verify installation of IHS, WAS, DB2, and MySQL and that they are running.
    ps -ef | grep IBMHttpServer
    ps -ef | grep WebSphere
    ps -ef | grep db2sysc
    ps -ef | grep mysqld
  2. Verify that you have the following tools in your PATH. If not you should add them or install them via RPM or YaST.
    gcc, libgcc, cpp, flex, bison, libxml2, libxml2-devel, zlib-devel, readline-devel, make, gunzip, tar
  3. Verify that you have root access.
  4. Though not necessary, you should take the system down to a single user run level, usually 1.

Installing PHP 5.0.3

  1. Download the source from php.net and place it in a temporary directory.
    mkdir src
    cd src
    wget http://SOME_MIRROR/php-5.0.3.tar.gz
  2. Unzip and untar the source.
    tar -zxvf php-5.0.3.tar.gz
  3. Modify the path to Perl in /opt/IBMHttpServer/bin/apxs. Change the first line from /usr/local/bin/perl to /usr/bin/perl
  4. Change to the PHP source directory and run configure. You may want to add other configure options, though you can always rerun the configure and following make steps later on. To see a list, type ./configure –help
    cd php-5.0.3
    ./configure \
    –prefix=/opt/local/php \
    –with-apxs=/opt/IBMHttpServer/bin/apxs \
    –with-mysql=/opt/local/mysql \
    –with-mysqli=/opt/local/mysql/bin/mysql_config \
    –with-libxml-dir=/usr/lib \
    –with-ibm-db2
  5. Stop IHS
    /opt/IBMHttpServer/bin/apachectl stop
  6. Run make (Thanks to Tim Gales for recommending the optional make test step).
    make
    make test
    make install

Configuring IBM HTTP Server to recognize PHP requests

  1. Since IHS is a modified Apache installation that allows you to build DSO modules, much of the following is standard Apache / PHP configuration.
    vi /opt/IBMHttpServer/conf/httpd.conf
  2. Verify that the correct AddModule and LoadModule directives were added by PHP. Ensure that the LoadModule directive appears above the AddModule directive.
    LoadModule php5_module libexec/libphp5.so
    AddModule mod_php5.c
  3. Instruct IHS to parse files with the standard PHP extension.
    AddType application/x-httpd-php .php
  4. You may also want to add index.php as a default directory index.
    DirectoryIndex index.html index.php

Ensuring that IBM HTTP Server still connects to WAS to process enterprise Java applications

  1. Prior to the installation of PHP, these two lines were appended to the bottom of httpd.conf, however, I had to move them up to where the other LoadModule directives were. Note: Make sure that there are no line breaks in these two directives, I’ve placed backslashes to indicate where they wrap in this article.
    LoadModule \
    ibm_app_server_http_module \
    /opt/WebSphere/AppServer/bin/mod_ibm_app_server_http.so
    WebSpherePluginConfig \
    /opt/WebSphere/AppServer/config/cells/plugin-cfg.xml
  2. I also had to add this line which didn’t previously exist.
    AddModule mod_ibm_app_server_http.c

Verify that IHS has been configured correctly

  1. Verify that IHS’s configuration file is free of typoes.
    /opt/IBMHttpServer/bin/apachectl configtest
  2. If it is, start the server.
    /opt/IBMHttpServer/bin/apachectl start
  3. If something goes wrong check the log files to isolate the error.
    tail -50f /opt/IBMHttpServer/logs/error_log
    tail -50f /opt/WebSphere/AppServer/logs/http_plugin.log

Update the WAS web server plugin

  1. Log in to the WebSphere Adminstrative Console at one of the following URLs.
    http://localhost:9090/admin
    https://localhost:9043/admin
  2. Expand the “Environment” twistie.
  3. Choose “Update Web Server Plugin” and click “OK.”

Verify that the web servers are working as expected

  1. I chose to restart IHS and WAS, for good measure.
  2. Verify that IHS is listening at port 80.
    http://localhost
  3. Verify that WAS is listening at port 9080 with any given context path.
    http://localhost:9080/PlantsByWebSphere
  4. Verify that both IHS and WAS are cooperating by calling the context path on port 80. This behavior should be as it was before we started the PHP install.
    http://localhost/PlantsByWebSphere
  5. Verify that IHS also knows about PHP by creating a test file with only phpinfo(); as its contents.
    /opt/IBMHttpServer/htdocs/en_US/ihs-test.php
  6. Call the PHP file via IHS.
    http://localhost/ihs-test.php
  7. If it displays PHP configuration information, crack open a beer.
  8. If not, head down to the bodega for a 40oz of Private Stock.

Verify that the database servers are working as expected

  1. Create another test file to ensure that PHP can connect to both DB2 and MySQL.
    /opt/IBMHttpServer/htdocs/en_US/db-test.php
  2. Ensure that you have a database created in both MySQL and DB2, as well as a user and password with which to connect.
  3. Add the following PHP code to the file, assuming that “sample” is the database name.

    To test the connection to DB2

    $db2 = odbc_connect(‘sample’, ‘user’, ‘pass’);
    odbc_close($db2);

    To test the connection to MySQL

    $mysqli = new mysqli(‘localhost’, ‘user’, ‘pass’, ‘sample’);
    $mysqli->close();
  4. Call the PHP file via IHS.
    http://localhost/db-test.php
  5. If there was no output, rejoice. Your basic set up is complete. You can begin writing PHP applications and locking down PHP via its configuration file.
    /opt/local/lib/php.ini

References

  

8 Responses to 'Configuring PHP 5 with IBM HTTP Server, WebSphere Application Server, and DB2 UDB'

Subscribe to comments with RSS

  1. Mike Adams said,

    17 November 2006 at 12:08 am

    Daniel – I have been trying to get this to work with IHS 1.3.26.

    I make it all the way to the make command. when I run make i get a bunch of similar messages as follows.

    /downloads/php/php-ihs/php-src/php-4.4.4/sapi/apache2handler/sapi_apache2.c:38:25: apr_strings.h: No such file or directory

    Is there anything I can do to solve this?

  2. krook said,

    17 November 2006 at 9:20 am

    Mike,

    I’ve noticed that my blog package seems to convert double-hyphens to m-dashes in my code snippets, so the “configure” command may be broken for you. This is probably why your PHP build is looking for Apache 2 instead of IHS, because it can’t make sense of the “with-apxs” flag.

    Convert the m-dashes to double hyphens before each of the “with” flags and see if that fixes the problem.

  3. Smith said,

    10 December 2006 at 12:44 am

    Thank for making this valuable information available to the public.

  4. Adam Klein said,

    13 December 2006 at 3:41 pm

    Daniel,

    I’ve been struggling with building PHP-5.2.0 on a SPARC T2000 with Solaris 10 and IHS 6.0.2 for a few days. I finally solved the configure and make problems by commenting out the sections of the configure script that check the Apache version for apxs. By forcing it to accept IHS6′s httpd -v version string as valid (which uses the apache version number, not the date – which is what the configure script checks), I got a successful build and install.

    A very useful tip is to do ‘make -j 32′ on a T2000. It’s _MUCH_ faster.

  5. Toine said,

    11 June 2009 at 6:17 pm

    Thx for the information.

    I changed it a bit to a New version.

    Very important is that the Development tools Are installed when installing DB2 express. So when installing select custom or Full.

    ‘./configure’ ‘–with-apxs2=/opt/IBM/HTTPServer/bin/apxs’ ‘–prefix=/usr/local/php’ ‘–with-gd=shared’ ‘–with-zlib’ ‘–enable-ftp’ ‘–with-libxml-dir=/usr’ ‘–with-mysql=/usr/bin/mysql’ ‘–with-mysqli=/usr/bin/mysql_config’ ‘–with-pdo-odbc=ibm-db2′ ‘–with-IBM_DB2=/opt/ibm/db2/V9.5/’

    regards Toine Eetgerink


  6. 09 April 2011 at 11:57 pm

    Operating System Windows XP Home Edition

    I installed:
    Apache 2.2.8
    PHP 5.2.5
    DB2 C Express v9.7 (catalog databse installed in the same machine as Apache and PHP)

    I installed and configured Apache and PHP. Both were tested and work
    fine together.
    I installed DB2 without problems.

    When I tried to configure PHP to work with DB2 I followed the instructions
    from:

    http://www.ibm.com/developerworks/xml/tutorials/x-xmldbjavaphp/section3.html

    it went through without problems until the section:

    **************************************************************************************
    Connecting to DB2 with PHP: Setup

    Before you can begin coding in PHP, you need to configure PHP with the IBM_DB2 module.

    Click the speedometer in the system tray. Then click PHP Settings > PHP extensions and

    select php_ibm_db2 from the long list, as in Figure 13.

    **************************************************************************************

    I have problems trying to find the speedometer in the system tray.
    Is the system tray of my machine? or maybe I looked in the wrong place.

    Can you please tell me how to find it. Or how to get to configure PHP with
    the IBM_DB2 module in another way?

    I will appreciate your response to solve this problem.

    Thanks and regards,
    Oscar G. Andrade.

  7. Daniel Krook said,

    11 April 2011 at 3:22 pm

    Hi Oscar,

    That resource that you linked to seems to have some old information.

    Fortunately, it should be pretty simple to connect the Apache, PHP, and DB2 you already have installed.

    First, if you don’t already have it, grab the latest threadsafe ibm_db2 extension for PHP 5.2 from SourceForge:
    http://sourceforge.net/projects/db2mc/files/IBM_DB2%20PHP%20Driver%20for%20Windows/PHP%205.2._/

    Then, copy the DLL to your PHP extensions directory. Mine was C:\PHP\ext as I specified in my php.ini file.

    Finally, I added the module to php.ini and restarted Apache. You may have to restart Windows if it still doesn’t pick up the extension.

    extension_dir=”c:\PHP\ext”
    extension=php_ibm_db2.dll

    Hope that helps,
    -Dan


  8. 25 November 2014 at 10:46 pm

    Предлагаем широкий выбор мягкой мебели в Минске и РБ, а также на заказ, качественные европейские материалы, любые размеры, скидки, гарантия 2 года. Также в наличии ортопедичесике матрасы, окна из ПВХ, натяжные потолки и огромный выбор лестниц. Услуги дизайнера, обмер, доставка, установка (по Минску) – бесплатно. Подробнее у нас на сайте: 699.by

Leave a Reply