Skip to main content

Hosting PHP applications on the IBM HTTP Server

You probably didn't know you could

Graham Charters (charters@uk.ibm.com), Senior Software Engineer, IBM U.K. Laboratories
Author1 photo
Graham Charters works at IBM's development lab in Hursley, England. Past roles have included IBM WebSphere® Application Server development, and architecture responsibilities in WebSphere Business Integration, and Adapters. His current interests are in the relationships between open source technologies, such as those of Linux®, Apache, MySQL, PHP/Perl/Python (LAMP) and the WebSphere platform. He holds degrees in computer science, numerical analysis, and machine vision, all from the University of Manchester.
Matthew Peters (matthew_peters@uk.ibm.com), Software Engineer, IBM UK Laboratories
Matthew Peters photo
Matthew Peters works at IBM's development lab in Hursley, England. He has worked in various roles on IBM's CICS and MQSeries products and also spent a number of years working with partners in scientific and technical computing and large-scale parallel processing. In recent years he worked on the garbage collector in the IBM JVM. Matthew has a degree in Mathematics from Queens' College, Cambridge and an MSc in Software Engineering from Oxford University.
Caroline Maynard (caroline.maynard@uk.ibm.com), Software Engineer, IBM UK Laboratories
Caroline Maynard photo
Caroline Maynard works at IBM's development lab in Hursley, England, where she has worked in diverse areas including networking, graphics and voice. Most recently she led the development of the IBM Java ORB, which underpins the WebSphere Application Server's EJB container. She is interested in the integration of IBM offerings with open-source LAMP (Linux, Apache, MySQL, Perl/Python/PHP) technologies. Caroline holds a degree in Mathematics from the University of Sussex.
Anantoju Srinivas (srinivas.anantoju@in.ibm.com), Staff Software Engineer, IBM Bangalore Laboratories
Anantoju V Srinivas
Anantoju Veera Srinivas works at IBM's development lab in Bangalore, India. Past roles have included JVM development on Linux® and AIX®. His current interests are in Web technologies and databases, such as Linux, Apache, MySQL, PHP/Perl/Python (LAMP) in the open source world, and the IBM WebSphere® and DB2® platforms. He holds degrees in electrical and electronics engineering from Sri Venkateshwara University, Andhra Pradesh, India.

Summary:  IBM® maintains its own copy of the Apache Web server and ships it as the IBM® HTTP Server, along with its WebSphere® Application Server. This Web server is fundamentally Apache and as such, can host and run applications written in PHP. Learn about the differences between the open source Apache Web server and IBM's version, and view demonstrations of IBM's version running a well-known PHP application.

Date:  24 Mar 2005
Level:  Intermediate
Activity:  3329 views

Introduction

For a number of years, IBM has been shipping the IBM HTTP Server as part of the WebSphere Application Server package. In the WebSphere-centric world, most of the hard work is done in the WebSphere Application Servers by applications written in the Java™ programming language, and the job of the humble Web server is to sit in front of the application servers and serve up static content: static HTML pages, applets, etc.

It turns out that IBM HTTP Server is a fully functional version of the Web's most popular Web server, Apache, and is capable of serving more than static content. It is able to run modules written to Apache's dynamic shared objects (DSO) interface and, in particular, it can host and run applications written in PHP.

Discover the similarities and differences between open source Apache and the IBM HTTP Server, and consider some reasons why you might prefer one to the other. Then, as a proof by example and to convince the skeptical, walk through the steps to get a representative and well-known open source PHP application, PHP-Nuke, running on IBM HTTP Server. To prove it is not a fluke, find out how to do it on both Windows® and Linux®.


What is the IBM HTTP Server? How does it differ from the open source Apache Web server?

First, the IBM HTTP Server is Apache. There are two versions of IBM HTTP Server, based in turn on 1.3 and 2.0 versions of open source Apache, but with small alterations to allow IBM to attach extra features. The code bases are maintained inside IBM, where IBM keeps them up to date by selectively picking up and applying bug fixes from the open source Apache CVS repository. IBM gives fixes to security bugs a very high priority. Importantly for people wanting to use PHP on IBM HTTP Server, IBM ensures that IBM HTTP Server is fully compatible with open source Apache, so modules compiled to run with Apache will run with IBM HTTP Server. (See Resources to download the IBM HTTP Server.)

The best place to look for a complete list of the alterations and additions that IBM makes is the IBM HTTP Server Web site or InfoCenter, which is the technical information that comes with IBM HTTP Server. Here is a list of the main differences; three of the most significant differences are discussed in the sections that follow:

Threading
IBM HTTP Server V2.0 is compiled multithreaded, something that is an option for V2.0 of the open source Apache Web server. Although this is not a problem for PHP itself, it can cause a problem for some nonthread-safe PHP extensions. This is discussed in detail later.
Secure Sockets Layer
IBM HTTP Server contains Secure Sockets Layer (SSL) support built-in with IBM's GSKit library. The usual open source choice is OpenSSL. The differences between GSKit and OpenSSL versions of SSL are discussed later.
LDAP
IBM HTTP Server can access an LDAP server to obtain user and group authentication for the Web server itself. This is intended for use in an environment where an administrator manages a number of Web servers and wants to maintain authentication information for the Web servers in a single place.
Performance
IBM HTTP Server contains two enhancements aimed at improved performance. The first of these is the "FastCache" accelerator, which on the Windows operating system and recently on AIX®, improves response time by caching pages in kernel memory. The second enhancement is that IBM HTTP Server comes with FastCGI support built in. FastCGI is an open extension to the Common Gateway Interface. It defines a protocol to talk to persistent CGI programs via a socket. This potentially removes a considerable overhead from the use of CGI programs.
Documentation
As mentioned, IBM HTTP Server comes with the InfoCenter, which is a comprehensive set of help pages, especially on the points where IBM HTTP Server differs from Apache — how to set up for use of SSL, how to set up for use of an LDAP server, etc. The documentation is provided in 10 languages.
Installation
IBM HTTP Server uses a Java-based InstallShield installer so that installation looks the same on various platforms. The installer comes with text in a number of languages, just like the InfoCenter. It can also be configured to run as a silent installation.
Source code
IBM does not ship the source code for IBM HTTP Server, just the binaries. This may be the biggest and most significant difference for some people, and is discussed later.

Multithreading, Apache V1.3 and 2.0

If you have worked with Apache and PHP for a while, you will likely have come across the warning in the install documentation that states not to use Apache V2.0.x and PHP in a production environment on UNIX or on Windows. In the PHP V5.0.2 package on the Windows system, this warning is to be found at line 745 in install.txt. It is worth understanding what the issues are so you can decide whether to use Apache V2.0 or IBM HTTP Server V2.0.

Apache V2.0 can be configured to run in one of two ways: threaded or nonthreaded. When running as a threaded server, multiple threads of execution can be active in the server at the same time, generating the reply to more than one user at once. In principle, this makes the server more responsive and better able to take advantage of bigger hardware with more processors. It introduces a hazard, however. All the various layers of software that the server calls must be safe to be called on behalf of more than user at the same time. Although the Web server itself, the PHP interpreter, and PHP extensions are all safe to be called this way, some PHP extensions make use of libraries written in other languages like C, and not all of these libraries are thread-safe.

You can find a pointer to an Apache Web page on the matter, with some more advice and a method for sometimes working out which C libraries your PHP extensions might be using, and which are thread-safe, in the Resources section.

In practice, many people choose to sidestep the issues and do one of two things: use Apache V2.0 in its single-threaded mode or use Apache V1,.3 which always runs single-threaded. Although there are some other differences between Apache V1.3 and V2.0, by far, the most significant difference is in this matter of threading, so remaining with a V1.3 server is not the drawback it might sound.

How does this play out for IBM HTTP Server? IBM builds IBM HTTP Server from Apache V2.0 in its threaded mode: faster but potentially unsafe with nonthread-safe extensions. And since IBM does not ship the source code, and the choice of threading or nonthreading is chosen at compile time, as an end user, you do not have the choice to recompile IBM HTTP Server V2.0 nonthreaded. At the time of writing, IBM is shipping V2.0- and V1.3-based versions of IBM HTTP Server, giving you the choice to use the single-threaded V1.3-based server.


SSL and GSKit

The Secure Sockets Layer (SSL) is the layer of software that permits secure and encrypted communications between the browser and the server. You know when your communication with the server is being carried over SSL when the URL of the Web site you are using starts with HTTPS and not HTTP. In Internet Explorer®, Netscape, or Firefox, a small padlock appears somewhere in the status bar of the browser.

SSL is not only responsible for encrypting the data being carried between browser and server but it can also be used to verify that the server you are connected to is indeed the Web site it claims to be, or for the user of the Web browser to verify that he is who he says he is.

IBM HTTP Server does not use the generally available open source implementation of SSL, OpenSSL, but uses instead IBM's GSKit library. This library is used by a number of IBM products, and the cryptography routines are embedded in a subcomponent called IBM Crypto for C (ICC), which has been certified against Federal Information Processing Standards (FIPS) on a variety of platforms, making it suitable for use by some parts of the U.S. Government. FIPS is specified by the U.S. National Institute of Standards and Technology (NIST), and the certification for ICC is available on the NIST site. A link to the certification, along with precise details of the tests performed, can be found in the Resources section.

In a nutshell, the version of SSL in IBM HTTP Server has been certified for use in some government applications.


No source code

As mentioned, IBM does not ship the source code for IBM HTTP Server, even though it is based on the open source Apache Web server. Instead, IBM supplies precompiled binaries for many common platforms and operating systems, both IBM and non-IBM: AIX, Sun Solaris, HP-UX, Linux (on a variety of hardware, including the zSeries®) and Windows. Distributing binaries and not source this way is quite in keeping with the Apache license under which the open source Apache Web server is distributed, by the way.

Whether having no source code comes as a blow or a blessed relief to you will probably depend on how you like to obtain service, support, and documentation. If you like the open source model of support: freely available source code, support through newsgroups, blogs, community Web sites, etc., you may dislike it. On the other hand, if you are comfortable with the IBM support model — IBM Redbooks, the IBM support Web sites, and IBM support personnel and processes — and you do not want to recompile the source code, you will be comfortable with IBM HTTP Server. Note that while IBM HTTP Server is freely downloadable, IBM provides service and support for IBM HTTP Server only when it has been purchased as part of WebSphere.


A working example: PHP-Nuke

Learn how to get PHP running on IBM HTTP Server by installing PHP-Nuke, a well-known PHP application. It does not matter if you know the application. PHP-Nuke is a content management system, which is software that provides a community with a Web site to host news, Web logs, etc.

This experiment was tried on Windows and Linux on a single-CPU Intel x86 machine. Windows XP, and Red Hat V9.0 and Red Hat Enterprise Linux V3, Update 3, were used. IBM HTTP Server, PHP, MySQL, phpMyAdmin, and finally PHP-Nuke itself were installed. Each section offers instructions for Windows and Linux. The installations of IBM HTTP Server, PHP, and MySQL differ on Windows and Linux, but the installations of phpMyAdmin and PHP-Nuke are similar on both operating systems.

Getting started

On Windows, you use the following at the following levels:

  • IBM HTTP Server V2.0.47.1
  • PHP V5.0.3
  • MySQL V4.0.23
  • phpMyAdmin V2.6.0-pl3
  • PHP-Nuke V7.5

You downloaded each as a ZIP file. There are two possible downloads for MySQL: download the ZIP file that includes an installer.

On Linux, use the following at the following levels:

  • IBM HTTP Server V6.0.0.0
  • PHP V5.0.3
  • MySQL V4.1.8
  • phpMyAdmin V2.6.0-pl3
  • PHP-Nuke V7.5

You will find the exact filenames of the Linux install files in the sections that follow.

The above were all current on the day they were downloaded (21 Dec 2004). Although PHP-Nuke V7.6 was available, it costs a small amount of money, so V7.5 was chosen, which was the most recent free version.

You may choose to deviate from either of these lists. On Windows, there were problems using the more recent MySQL V4.1.7, instead of V4.0.22. These had to do with the MySQL client library that comes with PHP V5.0.2 not being happy to talk to MySQL V4.1.7. It gave a 1251 error, suggesting the client library should be updated. Instead, MySQL V4.0 was chosen to make things easier. On Linux, the latest available levels of all the software were used with no problem.

Also, some parts of this scenario were tried using PHP V4.3.9, which worked fine. PHP V4 and V5 differ in their directory layout. Otherwise, it makes no difference to the scenario described here.

Your first step is to install IBM HTTP Server.

Installing and starting IBM HTTP Server

There are three steps here: unpacking the download, using the provided Java-based installer to perform the install, and starting IBM HTTP Server.

Depending on which version of IBM HTTP Server you are installing, you may need a version of the Java runtime on your machine. IBM HTTP Server V6.0.0 comes with the Java installer embedded within it, whereas IBM HTTP Server V2.0.47.1 does not. If you are running on AIX or Linux and you need to download a copy of the Java runtime, you may find one freely downloadable (see Resources). On other operating systems, you may need to download one from elsewhere: the Sun JVM is an obvious choice. The IBM HTTP Server installer does not seem to be very sensitive to the version of the JVM.

On Windows:

Win.1 Unzip the IBM HTTP Server download
Always unzip into C:\installs, so that you then find a setup.jar file in C:\installs\IHS-2.0.47.1\.
Win.2 Execute the install
Once you have a JVM installed and in your path, you should locate the setup.jar and execute it as follows:
C:\installs\IHS-2.0.47.1>java -jar setup.jar

The install dialog will ask you to:
  • Choose the language for the install
  • Accept the terms and conditions
  • Specify or allow to default the directory to contain IBM HTTP Server
  • Choose a setup type (Typical will do)
  • Enter a user ID and password under which it will run, since on Windows it will run as a service
Win.3 Start IBM HTTP Server
You have three ways to start it now:
  1. Start a Command Prompt window, navigate to where IBM HTTP Server is installed and execute the Apache command directly, though this is probably not what you want to do each time.
  2. Look for it as a Windows Service and start it in Start > Control Panel > Administrative Tools > Services.
  3. The third way is to find ApacheMonitor.exe in C:\Program Files\IBM HTTP Server 2.0\bin and start this, which then displays as the Apache feather in the notification area of the Windows toolbar in the bottom right-hand corner of the screen. Once the ApacheMonitor is running, you will be able to start, stop, and restart IBM HTTP Server from here, too.

On Linux:

Linux.1 Download and untar the install image
Download the IBM HTTP Server V6.0 (ihs.6000.linux.ia32.tar) from the IBM HTTP Server Web site (see Resources). Log on as root and untar the above file in your home directory. Always choose /root to untar into and the examples that follow will show this.
Linux.2 Locate the image and execute the install
Locate the install image and execute as follows, choosing the default values on all the screens:
[root@localhost /root] cd /root/IHS
[root@localhost /root/IHS] ./install

Linux.3 Start IBM HTTP Server
IBM HTTP Server installs by default into /opt/IBMIHS, so start it with the apachectl command as follows:
[root@localhost /root] /opt/IBMIHS/bin/apachectl start

When you later want to restart or stop the server, use the apachectl command with restart or stop.

Connect to IBM HTTP Server and check the installation

The steps here use a browser to connect to IBM HTTP Server and read the documentation. This process is much the same on Windows and Linux.

Open a browser and go to http://localhost to display the welcome page from IBM HTTP Server.


Figure 1. IBMS HTTP Server welcome screen
IHS welcome screen

The View Documentation link will take you to the InfoCenter pages, where you can find out more about the extras IBM has added to IBM HTTP Server. The InfoCenter does not display properly with the Windows version of Firefox, unfortunately, but works fine with Internet Explorer. On Linux, it displays fine with Firefox.


Figure 2. IBM HTTP Server InfoCenter
IHS - View Documentation

Installing MySQL

The steps in this section cover installing MySQL, starting it, and setting the password for the root user. MySQL has many ways of achieving the same thing. Here are the commands to get MySQL configured and the PHP-Nuke database created in as few steps as possible. It may be that you have some experience with MySQL and know other ways of achieving the same thing, in which case please feel free to deviate from the steps listed here. The installation process is quite different between Windows and Linux.

On Windows:

Win.1 Unzip and install
MySQL comes with a Windows installer, so it is recommended you start there by unzipping the download and executing setup.exe. The only questions asked during the install for V4.0.23 are the basics: where to install (default location is C:\mysql) and install type — typical is fine. If you experiment with V4.1, you will find the installer asks more questions and does more during installation.
Win.2 Install MySQL as a service and start it
Install MySQL as a Windows service to start automatically. You need a command window from which to run the MySQL executables. Open a command window in C:\mysql\bin:
C:\mysql\bin>mysqld-nt --install

Go to the Windows Services window (Start > Control Panel > Administrative Tools > Services), find MySQL and start it.

Win.3 Set the password for the root user
Assuming you are connected to a network, you might want to set a password to control access. Once started, MySQL is listening on a socket for connections. Here set the password for the user ID "root" to the rather poorly chosen password "root" (only one step better than password "password").This is not a recommended password. You will use whatever password you choose later.

Another consideration is that in the steps that follow you might not wish to use the MySQL user root but create one especially for the use of phpMyAdmin and PHP-Nuke. That's fine. Choose root, since it is there by default.

Note that this user ID "root" is not a Windows user ID, but private to MySQL — more like a user administration role. The precise interaction — starting the mysql command-line client and entering the command to set the password for connections from the local machine — looks like this:

C:\mysql\bin>mysql -u root
Welcome ... [text omitted]
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
Query OK, 0 rows affected (0.00 sec)
mysql>quit
Bye
C:\mysql\bin>

On Linux:

Linux.1 Download the install images
Download MySQL V4.1.8 for i386 from the MySQL Web site Resources. Download the following files:
  • MySQL-server-4.1.8-0.i386.rpm
  • MySQL-shared-4.1.8-0.i386.rpm
  • MySQL-devel-4.1.8-0.i386.rpm
  • MySQL-client-4.1.8-0.i386.rpm
Linux.2 Install MySQL binaries
Log on as root and place all the above files in your home directory, say /root. Change directory to /root and execute the rpm command to install all four packages.
[root@localhost /root] rpm -ivh MySQL-*

Linux.3 Start MySQL server
There are many ways to start the MySQL server. It is usually started from the command line, using either of the following two commands:
[root@localhost /root] /etc/init.d/mysql start

or
[root@localhost /root] service mysql start

If you later want to stop it, you can use either of the same commands with the option stop.
Linux.4 Set the password for the root user
Assuming you are connected to a network, you might want to set a password to control access, as once started, MySQL is listening on a socket for connections. In the examples here, set the password for the MySQL user "root" to the rather poorly chosen password "root" (only one step better than password "password"). Note that this user ID "root" is not in any way related to the Linux root user ID but private to MySQL — more like a user administration role. It is not recommended to use "root" as the password! You will use whatever password you choose later.

Another consideration is that in the steps that follow, you might not wish to use the MySQL user root, but create one specially for the use of phpMyAdmin and PHP-Nuke. That's fine. Choose root, since it is there by default. Set the password as follows:

[root@localhost /root] mysqladmin -u root password root

Installing PHP and linking IBM HTTP Server and PHP together

The steps here differ substantially between Windows and Linux because on Windows you use a precompiled binary, whereas on Linux, you configure and compile the PHP interpreter. The aim is the same in both cases: to create and populate the PHP directory structure, to configure an appropriate php.ini configuration file, and to configure IBM HTTP Server so it runs files with a .php extension through the PHP interpreter.

On Windows:

Win.1 Unzip the PHP install
Begin by unzipping the downloaded PHP ZIP file. There is no installer, and you can choose where the php directory should go. Stick with the traditional C:\php.
Win.2 Create php.ini
You need to select a php.ini file from one of the two supplied: php.ini-dist or php.ini-recommended. There is some discussion of the difference between the two in the C:\php\install.txt file, which says that the latter has better performance and security. Take a copy of C:\php.ini-recommended and name it C:\php\php.ini.
Win.3 Place directives in httpd.conf
You now need to add three lines to the IBM HTTP Server config file so that IBM HTTP Server can find PHP, load the PHP module, and associate the file extension .php with the PHP interpreter.

Assuming you installed IBM HTTP Server in the default place, the IBM HTTP Server config file will be in C:\Program Files\IBM HTTP Server 2.0\conf\httpd.conf, and the three lines you need to add are:

PhpIniDir c:/php
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

Note the forward slashes in the otherwise normal Windows directory and file names; they are correct. You can be tidy and put the statements in their proper places within the config file, but it works just as well to cut and paste them in as a unit and keep them all together. Put them as a unit just before the first of the other LoadModule statements. You will need to edit the PhpIniDir directive if you have put PHP anywhere other than C:\php.

Win.4 ensure php5ts.dll can be found
You'll also need to ensure that Windows can find and load an essential PHP DLL using the normal Windows DLL loading process. The DLL in question is C:\php\php5ts.dll (the ts stands for thread-safe) and you have two ways to get it picked up: You can put C:\php in your PATH, or you can copy C:\php\php5ts.dll to the same directory as the IBM HTTP Server executable, which is C:\Program Files\IBM HTTP Server 2.0\bin. Within our group, opinions are split about which is the better method.
Win.5 Restart IBM HTTP Server to pick up the changes
Now restart IBM HTTP Server. You can do this from Start > Control Panel > Administrative Tools > Services or using the ApacheMonitor.

On Linux:

Linux.1 Download and untar
Download the PHP V5.0.3 sources (php-5.0.3.tar.bz2) Resources and untar as follows:
[root@localhost /root] tar -xjvf php-5.0.3.tar.bz2

Linux.2 Configure and compile the source
Change directory to php-5.0.3 and configure and compile the sources with the following four options as shown. This is all one command that has been laid out for readability. Compiling may take several minutes depending on your machine processor, memory, etc.:
[root@localhost /root/php-5.0.3] ./configure --with-apxs2=/opt/IBMIHS/bin/apxs 
                                 --with-mysql=/usr  
                                 --with-config-file-path=/opt/IBMIHS/conf 
                                 --enable-maintainer-zts
[root@localhost /root/php-5.0.3] make

The final option, --enable-maintainer-zts, causes the PHP interpreter to be compiled to run safely with a threaded Web server like IBM HTTP Server: "zts" stands for Zend Thread Safe or something like it. Note you will need to recompile. If you do manage to find and download a precompiled PHP for Linux, it will likely not have been compiled with thread-safety on, and when IBM HTTP Server loads the PHP interpreter, it does check, and will issue an error message if the PHP has been compiled in a way that is thread-safe.
Linux.3 Copy the PHP shared library
Copy the built module into the IBM HTTP Server modules directory:
[root@localhost /root/php-5.0.3] cp .libs/libphp5.so /opt/IBMIHS/modules

Linux.4 Create php.ini
You need to select a php.ini file from one of the two supplied: php.ini-dist or php.ini-recommended. There is some discussion of the difference between the two in the install.txt file, which says that the latter has better performance and security. Copy the php.ini-recommended to IBM HTTP Server Configuration directory as php.ini:
[root@localhost /root/php-5.0.3] cp php.ini-recommended /opt/IBMIHS/conf/php.ini

Linux.5 Place directives in httpd.conf
Add the following lines into IBM HTTP Server's httpd.conf (if you installed IBM HTTP Server at the default location, this file is available at /opt/IBMIHS/conf/httpd.conf) by opening the same into your favorite editor. You can add these lines anywhere you wish, but preferably, add these lines immediately after all the LoadModule statements in the above file.
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .php3 .phtml
AddType application/x-httpd-php-source .phps

Linux.6 Restart IBM HTTP Server to pick up the changes
Now restart IBM HTTP Server.
[root@localhost /root] /opt/IBMIHS/bin/apachectl restart

The next step is to get a PHP page displayed.

Check the PHP installation

The steps here are to create a page that uses PHP and to display it. Only the location of the page, not the content, differs between Windows and Linux. You may have a PHP page, but if not, you will find you get a lot of output for very little effort with the following complete-as-it-stands PHP script:

<? echo phpinfo(); ?>

Insert this line, all 21 characters of it, into a file called test.php and place this file where IBM HTTP Server can find and load it. See below for the correct location for the file.

Win.1 Locate the test.php file on Windows
If you installed IBM HTTP Server with English as the default language, this will be in the directory C:\Program Files\IBM HTTP Server 2.0\htdocs\en_US. If you installed IBM HTTP Server with a different default language, the final part of the directory name will specify a different language. In either case, the directory to place it is that specified by the DocumentRoot directive in the IBM HTTP Server config file, C:\Program Files\IBM HTTP Server 2.0\conf\httpd.conf.
Linux.1 Locate the test.php file on Linux
If you installed IBM HTTP Server with English as the default language this will be in the directory /opt/IBMIHS/htdocs/en_US. If you installed IBM HTTP Server with a different default language, the final part of the directory name will specify a different language. In either case, the directory to place it is that specified by the DocumentRoot directive in the IBM HTTP Server config file, /opt/IBMIHS/conf/httpd.conf.

Now start a browser and direct it to http://localhost/test.php. With luck, you will see a screen like that below.


Figure 3. Output from test.php script
phpinfo()

If you don't see the screen above, the two most likely other things you might see are:

  • A screen containing the PHP text you typed in <? echo phpinfo(); ?>. We saw this when we forgot to restart IBM HTTP Server, so IBM HTTP Server had not picked up the changes we had made to httpd.conf and, therefore, did not recognize the file extension .php as meaning that the file should be run through the PHP interpreter.
  • A completely blank screen (although if you view the source of the page, it does contain some HTML tags, just no visible content). We saw this when we had made a mistake in entering the test.php script. In this case, we found that there was a useful error message containing the text "...PHP Parse error: syntax error in ... test.php" in the IBM HTTP Server error log file, which on Windows will be found in C:\Program Files\IBM HTTP Server 2.0\logs\error.log and on Linux in /opt/IBMIHS/logs/error.log.

    You may consider that this message would be more useful if written back to the browser, but this is a deliberate consequence of choosing php.ini-recommended file and not php.ini-dist as the basis for the php.ini file. It is considered a benefit to security that errors are written to the error log and not the browser, and, hence, nothing is given away about the setup on the server. If you want the messages to be sent back to the browser then use php.ini-dist as the basis for your php.ini.

If you have gotten this far, you have a working IBM HTTP Server and PHP system and are ready to configure PHP to talk to MySQL.

Configuring PHP to access MySQL

Here the steps are to ensure that PHP can find the MySQL libraries. This is only needed for Windows. On Linux, the linkage was created when the PHP interpreter was compiled.

On Windows:

Win.1 Configure the php.ini file so PHP can find MySQL
Now you have to make sure that PHP knows how to find and load the PHP extension that will let it talk to MySQL. Edit your php.ini file and do the following:

Look for the line that specifies the php_mysql.dll extension and uncomment it by removing the semicolon. After uncommenting, the lines in the vicinity look like this in our php.ini:

;extension=php_msql.dll
extension=php_mysql.dll
;extension=php_oci8.dll

Make sure the PHP extension can be found by setting the extension_dir variable correctly. A little higher up the file, you should see this variable, set by default to "./". Change this to point to the extensions directory in your installation of php as follows:

extension_dir = "c:\php\ext"

Win.2 Ensure that the MySQL DLL can be loaded
The other half of the PHP to MySQL connection is the MySQL library libmysql.dll that is provided in C:\php\ext. When starting IBM HTTP Server, Windows is going to need to load this using its usual DLL loading procedure. As before, you have a choice: You can add C:\php\ext to your PATH or you can copy the DLL to directory containing the IBM HTTP Server executable, C:\Program Files\IBM HTTP Server 2.0\bin.
Win.3 Restart IBM HTTP Server
You now have to restart IBM HTTP Server so PHP can reread the php.ini file.

Unfortunately, it is all too easy to make a mistake in these final steps. If you get the message "Unable to load dynamic link library...php_mysql.dll," it will be because of this. It is hard to give clearer advice, but one thing to remember is that although the message mentions php_mysql.dll it may in fact be failing because it cannot find libmysql.dll.

Installing phpMyAdmin

The steps here are to unpack the phpMyAdmin PHP code into a place where it can be loaded by IBM HTTP Server, and to specify the MySQL root password that you set in the previous step in the phpMyAdmin config file.

It is not strictly necessary to install phpMyAdmin, but it is a very useful way to test the connection between PHP and MySQL, and it is likely that you will want it in due course anyway. Because the phpMyAdmin is a PHP application, the code is the same on Windows as it is on Linux. Only the location into which the files must be placed differ.

On Windows:

Win.1 Unpack the phpMyAdmin code
Unzip the phpMyAdmin ZIP file and copy the contents to a directory where IBM HTTP Server can find it: as before if you installed IBM HTTP Server with English as the default language it will be C:\Program Files\IBM HTTP Server 2.0\htdocs\en_US else one where the final part of the directory name is different. Copy it and rename it without the 2.6.0-pl3 in the directory name so that the precise directory structure we ended up with had a file C:\Program Files\IBM HTTP Server 2.0\htdocs\en_US\phpMyAdmin\index.php.
Win.2 Enter the MySQL root password in phpMyAdmin config file
You now need to edit the phpMyAdmin configuration file so it knows the root password for MySQL you entered in an earlier step:

Edit C:\Program Files\IBM HTTP Server 2.0\htdocs\en_US\phpMyAdmin\config.inc.php, and near line 84, you should find the lines specifying the root user ID and password. The relevant section of our file looks like this, with the added password highlighted:

$cfg['Servers'][$i]['auth_type']     = 'config';    // ...
$cfg['Servers'][$i]['user']          = 'root';      // ...
$cfg['Servers'][$i]['password']      = 'root';       // ...
                                                    // ...

On Linux:

Linux.1 Download and unpack the phpMyAdmin code
Download the phpMyAdmin (phpMyAdmin-2.6.0-pl3.tar.bz2) Resources and untar it into the IBM HTTP Server htdocs directory as follows. As before, if you installed IBM HTTP Server with English as the default language, it will be /opt/IBMIHS/htdocs/en_US, else one where the final part of the directory name is different:
[root@localhost /opt/IBMIHS/htdocs/en_US] tar -xjvf /root/phpMyAdmin-2.6.0-pl3.tar.bz2

We renamed it without the 2.6.0-pl3 in the directory name so that the precise directory structure we ended up with had a file /opt/IBMIHS/htdocs/en_US/phpMyAdmin/index.php.
Linux.2 Enter the MySQL root password in phpMyAdmin config file
You now need to edit the phpMyAdmin configuration file so that it knows the root password for MySQL that you entered in the previous step:

Edit /opt/IBMIHS/htdocs/en_US/phpMyAdmin/config.inc.php, and near line 84 you should find the lines specifying the root userid and password. The relevant section of our file looks like this, with the added password highlighted:

$cfg['Servers'][$i]['auth_type']     = 'config';    // ...
$cfg['Servers'][$i]['user']          = 'root';      // ...
$cfg['Servers'][$i]['password']      = 'root';       // ...
                                                    // ...

You should now be able to connect to http://localhost/phpMyAdmin/index.php. With luck, you will see the following screen.


Figure 4. phpMyAdmin initial screen
phpMyAdmin screen

There are two other likely possibilities for what you might see. These are both problems that only occurred for us on Windows:

  • If you are unlucky, you will see the message beginning with the code 1251 and you have run afoul of the problem we had running MySQL V4.1 against PHP V5.0.3 on Windows. You will recall that we fell back to MySQL V4.0 for this reason.
  • A screen with the message "cannot load mysql extension." This will occur if PHP is unable to find and load the PHP to MySQL extension. This can be a defect in the php.ini file or because Windows is unable to find one of the MySQL library files, php_mysql.dll or libmysql.dll. Please look again at the final paragraphs of the section on Configuring PHP to access MySQL above.

You are ready for the final step: install PHP-Nuke.

Installing PHP-Nuke

The steps here are to unpack the PHP-Nuke code into a place where it can be loaded by IBM HTTP Server, to create the PHP-Nuke database and tables in MySQL, and to specify the MySQL root password in the PHP-Nuke config file.

On Windows:

Win.1 Unpack the PHP-Nuke code
First step is to unzip the ZIP file and copy part of the contents into the appropriate place. The unzipped version contains a directory HTML, which is the executable PHP part of PHP-Nuke. We copied this HTML directory into IBM HTTP Server's htdocs directory and renamed it "nuke" so that we had the file C:\Program Files\IBM HTTP Server 2.0\htdocs\en_US\nuke\index.php.
Win.2 Create the PHP-Nuke database and tables
Now you need to create the PHP-Nuke database in MySQL. Since you have to use MySQL to create the tables, we might as well create the database using MySQL, although you could just as easily do so using phpMyAdmin.

The following commands will prompt you for the MySQL root password you specified before. You also need to know where to find the file containing SQL commands that will create the PHP-Nuke tables. This file is also in the unzipped install directory. We unzipped PHP-Nuke into C:\installs, so we had a file C:\installs\PHP-Nuke\sql\nuke.sql. This is the file you need.

The interaction with MySQL to create the database and execute the commands to create the PHP-Nuke tables looks as follows:

C:\mysql\bin>mysql -u root -p 
Enter password: ****
Welcome....[text omitted]
mysql> create database nuke;
Query OK, 1 row affected (0.00 sec)
mysql> use nuke;
Database changed
mysql>source C:\installs\PHP-Nuke\sql\nuke.sql
[string of Query OK messages]
mysql>exit
Bye
C:\mysql\bin>

Win.3 Configure PHP-Nuke to know MySQL root password
The last thing to do is to let PHP-Nuke know the password you specified when you installed MySQL so it can access the nuke database you just created. The password is specified in config.php, which you will find in the same directory with PHP-Nuke's other PHP files, which for us was C:\Program Files\IBM HTTP Server 2.0\htdocs\en_US\nuke. Change the assignment to the $dbpass variable as shown by the highlighted change below:
$dbhost = "localhost";
$dbuname = "root";
$dbpass = "root";
$dbname = "nuke";
$prefix = "nuke";

On Linux:

Linux.1 Download and unpack the PHP-Nuke code
Download PHP-Nuke 7.5 (PHP-Nuke-7.5.zip) into /root, then create a directory called nuke in /opt/IBMIHS/htdocs/en_US, cd to it, and unzip the download directly in there:
[root@localhost /opt/IBMIHS/htdocs/en_US/nuke] unzip /root/PHP-Nuke-7.5.zip

Linux.2 Create the PHP-Nuke database and tables
Now you need to create the PHP-Nuke database in MySQL. Since you have to use MySQL to create the tables, we might as well create the database using MySQL, although you could just as easily do so using phpMyAdmin.

The following commands need you to include the MySQL root password you specified before. You also need to know where to find the file containing SQL commands that will create the PHP-Nuke tables. This file is also in the untarred install directory. We untarred PHP-Nuke under IBM HTTP Server's htdocs directory so the SQL commands will be found in /opt/IBMIHS/htdocs/en_US/nuke/sql/nuke.sql.

The interaction with MySQL to create the database and execute the commands to create the PHP-Nuke tables looks as follows:

[root@localhost /opt/IBMIHS/htdocs/en_US/nuke] mysql --user=root --password=root
mysql> create database nuke;
mysql> use nuke;
mysql> source /opt/IBMIHS/htdocs/en_US/nuke/sql/nuke.sql

Linux.3 Configure PHP-Nuke to know MySQL root password
The last thing to do is to let PHP-Nuke know the password you specified when you installed MySQL, so that it can access the nuke database you just created. The password is specified in config.php, which you will find in the same directory with PHP-Nuke's other PHP files, which for us was /opt/IBMIHS/htdocs/en_US/nuke. Change the assignment to the $dbpass variable as shown by the highlighted change below:
$dbhost = "localhost";
$dbuname = "root";
$dbpass = "root";
$dbname = "nuke";
$prefix = "nuke";

If you use phpMyAdmin to browse the database, you should be able to see the tables created.


Figure 5. PHP-Nuke tables in phpMyAdmin
PHP-Nuke tables in phpMyAdmin

If that is all in place, you should be ready to go to the initial page of the PHP-Nuke site you just installed and initialized. Go to http://localhost/nuke/index.php, and you should see:


Figure 6. PHP-Nuke initial screen
PHP-Nuke initial screen

If you do not see this, you may instead see a screen saying "There seems to be a problem with the MySQL server, ..." We saw this when we had not correctly specified the database password in the config.php file, as described.

At this point, you may want to check that the site is functioning correctly by creating a user ID and posting news on the site, and you will find a tutorial describing how to do so on PHP-Nuke's Web site. This is the point, that having proved the point that PHP-Nuke will install and run on IBM HTTP Server, at which this article stops.


Summary

It's as simple to run PHP on the IBM HTTP Server as it is with the open source Apache Web server, for the good reason that IBM HTTP Server is Apache with a few extra features. If the features are valuable to you and if the absence of source code is not a problem, you may prefer IBM HTTP Server. A well-known application, PHP-Nuke, runs on IBM HTTP Server as well as it does on Apache. Although it is not demonstrated here, another well-known content management/portal system, Mambo, also runs fine on IBM HTTP Server. In fact, assuming that you stick to running PHP extensions that are known only to call thread-safe C libraries on IBM HTTP Server V2.0, or perhaps simply use IBM HTTP Server V1.3, you should get along fine hosting your PHP applications on the IBM HTTP Server.


Resources

Learn

  • Visit Apache to learn about Apache 2.0 thread saftey issues, and learn which C libraries are thread-safe and can be safely used with Apache or IHS in threaded mode.

  • Visit the U.S. National Institute of Standards and Technology (NIST) for details of the Federal Information Processing Standards (FIPS) certification for the cryptography component in IBM HTTP Server.

  • PHP.net is the central resource for PHP developers.

  • Check out the "Recommended PHP reading list."

  • Browse all the PHP content on developerWorks.

  • Expand your PHP skills by checking out IBM developerWorks' PHP project resources.

  • To listen to interesting interviews and discussions for software developers, check out developerWorks podcasts.

  • Using a database with PHP? Check out the Zend Core for IBM, a seamless, out-of-the-box, easy-to-install PHP development and production environment that supports IBM DB2 V9.

  • Stay current with developerWorks' Technical events and webcasts.

  • Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.

  • Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.

  • Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand demos.

Get products and technologies

Discuss

About the authors

Author1 photo

Graham Charters works at IBM's development lab in Hursley, England. Past roles have included IBM WebSphere® Application Server development, and architecture responsibilities in WebSphere Business Integration, and Adapters. His current interests are in the relationships between open source technologies, such as those of Linux®, Apache, MySQL, PHP/Perl/Python (LAMP) and the WebSphere platform. He holds degrees in computer science, numerical analysis, and machine vision, all from the University of Manchester.

Matthew Peters photo

Matthew Peters works at IBM's development lab in Hursley, England. He has worked in various roles on IBM's CICS and MQSeries products and also spent a number of years working with partners in scientific and technical computing and large-scale parallel processing. In recent years he worked on the garbage collector in the IBM JVM. Matthew has a degree in Mathematics from Queens' College, Cambridge and an MSc in Software Engineering from Oxford University.

Caroline Maynard photo

Caroline Maynard works at IBM's development lab in Hursley, England, where she has worked in diverse areas including networking, graphics and voice. Most recently she led the development of the IBM Java ORB, which underpins the WebSphere Application Server's EJB container. She is interested in the integration of IBM offerings with open-source LAMP (Linux, Apache, MySQL, Perl/Python/PHP) technologies. Caroline holds a degree in Mathematics from the University of Sussex.

Anantoju V Srinivas

Anantoju Veera Srinivas works at IBM's development lab in Bangalore, India. Past roles have included JVM development on Linux® and AIX®. His current interests are in Web technologies and databases, such as Linux, Apache, MySQL, PHP/Perl/Python (LAMP) in the open source world, and the IBM WebSphere® and DB2® platforms. He holds degrees in electrical and electronics engineering from Sri Venkateshwara University, Andhra Pradesh, India.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Web development
ArticleID=83765
ArticleTitle=Hosting PHP applications on the IBM HTTP Server
publish-date=03242005
author1-email=charters@uk.ibm.com
author1-email-cc=cappel@us.ibm.com
author2-email=matthew_peters@uk.ibm.com
author2-email-cc=tomyoung@us.ibm.com
author3-email=caroline.maynard@uk.ibm.com
author3-email-cc=cappel@us.ibm.com
author4-email=srinivas.anantoju@in.ibm.com
author4-email-cc=cappel@us.ibm.com

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers