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
- 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
- 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
- Verify that you have root access.
- Though not necessary, you should take the system down to a single user run level, usually 1.
Installing PHP 5.0.3
- Download the source from php.net and place it in a temporary directory.
- Unzip and untar the source.
tar -zxvf php-5.0.3.tar.gz
- Modify the path to Perl in /opt/IBMHttpServer/bin/apxs. Change the first line from /usr/local/bin/perl to /usr/bin/perl
- 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
- Stop IHS
- Run make (Thanks to Tim Gales for recommending the optional make test step).
Configuring IBM HTTP Server to recognize PHP requests
- Since IHS is a modified Apache installation that allows you to build DSO modules, much of the following is standard Apache / PHP configuration.
- 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
- Instruct IHS to parse files with the standard PHP extension.
AddType application/x-httpd-php .php
- 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
- 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.
- I also had to add this line which didn’t previously exist.
Verify that IHS has been configured correctly
- Verify that IHS’s configuration file is free of typoes.
- If it is, start the server.
- 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
- Log in to the WebSphere Adminstrative Console at one of the following URLs.
- Expand the “Environment” twistie.
- Choose “Update Web Server Plugin” and click “OK.”
Verify that the web servers are working as expected
- I chose to restart IHS and WAS, for good measure.
- Verify that IHS is listening at port 80.
- Verify that WAS is listening at port 9080 with any given context path.
- 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.
- Verify that IHS also knows about PHP by creating a test file with only phpinfo(); as its contents.
- Call the PHP file via IHS.
- If it displays PHP configuration information, crack open a beer.
- If not, head down to the bodega for a 40oz of Private Stock.
Verify that the database servers are working as expected
- Create another test file to ensure that PHP can connect to both DB2 and MySQL.
- Ensure that you have a database created in both MySQL and DB2, as well as a user and password with which to connect.
- Add the following PHP code to the file, assuming that “sample” is the database name.
To test the connection to DB2
To test the connection to MySQL$mysqli = new mysqli(‘localhost’, ‘user’, ‘pass’, ‘sample’);
- Call the PHP file via IHS.
- 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.