If you are interested in watercolor paintings you can click here

How-to compile PHP 4.3.x and PHP 5.0.x

Last Update: 12/08/2004

As I said before this page has been updated to reflect the modification which are required to compile successfully PHP on the iSeries with the GNU GCC compiler. I went probably trough the same burden as Rob Ward. So, I hope that will help somebody else. The original document of IBM which help Rob and I a lot, can be found here : "Bringing PHP to Your IBM eserver iSeries Server"

System Requirements

  • OS/400 V5R2 or later
  • OS/400 PASE environment (5722-SS1 Option 33)
  • System Openness Includes (5722-SS1 Option 13)
  • HTTP Server for iSeries (5722-DG1)
  • Latest CUME and Group PTFs for above products

Other Requirements

Optional Tools

IBM suggest a PRPQ which is 5799-PTL. The status for now of this PRPQ is "trial and betas", so you can download it for free right now. This package contains iSeries Tools for Developers, which contains Perl 5.005_03 along with other tools.  For a full list of utilities in the Tools package go to http://www-1.ibm.com/servers/enable/site/porting/tools/list.html

Perl is required to compile many open source software.  However, you do not need this PRPQ if all you want is Perl.  Binaries for iSeries PASE are available at the Comprehensive Perl Archive Network http://www.cpan.org

Getting Prerequisite Tools Installed

Perl for iSeries PASE

  1. Download the Perl 5.8.0 iSeries PASE binaries from CPAN website at http://www.cpan.org/ports/os400/
  2. Uncompress the zipped tarball.  (I used Winzip for Windows)
  3. Create the folder perlpkg in the QOpenSys file system and copy the uncompressed tarball to the new folder.  (I used iSeries Navigator to create the folder and copy the uncompressed tarball)
  4. Start a PASE terminal session by entering CALL QP2TERM in your 5250 terminal session
    • Enter command: cd /QOpenSys/perlpkg
    • Enter command: tar -xvf  perl-5.8.0@18380-os400.tar (this will install Perl in /QOpenSys/perl)
  5. For easier access to the Perl utilities I created symbolic links to the /usr/bin folder
    • Enter command: ln -fs /QOpenSys/perl/bin/*   /QOpenSys/usr/bin
      This will create symbolic links to the Perl binaries in the /QOpenSys/usr/bin folder which is part of the standard PATH environment variable. 
    • If you want to see what your PATH environment variable contains enter the command: env PATH
  6. To make sure Perl installed correctly enter command: perl -v
    The command should return:
    This is perl, v5.8.0 built for aix
    (with 1 registered patch, see perl -V for more detail)
    Copyright 1987-2002, Larry Wall
    etc...

Install the GNU GCC compiler for AIX

  1. Download the free gcc binary that you can find here ftp://aixpdslib.seas.ucla.edu/pub/gcc/RISC/5.1/exec/.

    I chose to use the AIX 5.1 version because that was supported by my test machine which run with OS/400 version 5.2. In fact the PASE environment of OS/400 5.2 is built with the AIX runtime 4.3, 5.1 and 5.2.   I also chose the latest version of gcc available on the above website which is 3.3.4.

  2. As it is a binary archive, you must upload it to the QOpenSys directory. After that, you can uncompress it with the uncompress command :
    • Enter command: uncompress   gcc.xxxx.tar.Z
    That will give you a tar file. You can then untar it with the following command :
    • Enter command: tar -xvf   gcc.xxxx.tar

    This is important to do this in the QOpenSys directory, because when you will untar the archive that will create a directory tree which start by usr, and there is a pre-built directory called "usr" in the QOpenSys directory. It is also important to put it there because this file system support long names. and you can have long names with open-source software. It is also important to know that the "local" subdirectory of /QOpenSys/usr don't exist if you do a fresh install. The fact that you untar gcc will create it. You must also know that most of the open-source software need to use the /usr/local directory that's why we nedd to do the following step.

  3. Create a symbolic link bettween /usr/local and /QOpenSys/usr/local. To do that you must enter the following commands :
    • Enter command: cd /usr
    • Enter command: ln -s /QOpenSys/usr/local local

  4. Now, I advise you to create a file called .profile in your home directory where you can add the following line.
    • export PATH=$PATH:/usr/local/bin

    This will allow you to have the gcc compiler ready to use. If not, you will have to type in time you want to use the gcc compiler his full path. You can also type the above command in a QPTERM session.

  5. Start a PASE terminal session by entering CALL QP2TERM in your 5250 terminal session (if one is not already open)
  6. You can check that gcc is working fine by typing gcc -v. If erverything is fine that should return you some information about gcc and among them the gcc version.

    • Enter command: gcc  -v

Installing / Compiling PHP 4.3.x or PHP 5.0.x

You will have in some cases to interpret the instructions, so they will fit your environment. In general you will be following the instructions in the Redpaper with the exceptions below:

  1. Download the source for PHP v4.3.x or PHP 5.0.x from http://www.php.net (NOTE: PHP 4.3.0 had a serious security flaw in it which 4.3.1 fixes.  The fix to the flaw is the only difference between 4.3.0 and 4.3.1)
  2. Create the folder phppkg in the QOpenSys file system and copy the php-x.x.x.tar.gz file to it.
  3. Issue CD command to change directories to phppkg (cd /QOpenSys/phppkg )
  4. Uncompress the php-x.x.x.tar.gz file by issuing command: gzip -dc  php-x.x.x.tar.gz |  tar xvf -. Be careful, don't forget the dash at the end of the command
  5. Since PHP needs to be patched to recognize DB2/400 you will need to download the patched file that I provide here. Be careful, there is two version one for the PHP 4.3.x series and another one for the PHP 5.0.x series. There is 2 sources files in there (php_odbc.c and php_odbc_include.h). So, of course, you can checked the source. They have been modified according to the patch of IBM that you can find here. You can now replace the existing files that you can find in this directory : /QOpenSys/phppkg/php-x.x.x/ext/odbc. By the way, Rob Ward provide the same patched file.
  6. Remarks : if you want to install or to compile PHP v5.0.2, there is a required pre-requisite : libxml2 must be installed. Personnaly, I used the version 2.6.15 that you can find here. You can upload this archive in /QOpenSys/usr/local and uncompress it with gzip -dc libxml2-2.6.15.tar.gz | tar xvf - (don't forget the dash at the end). When the archive is decompressed you will find a directory called libxml2-2.6.15. Just do a "cd" into it. Then you can use the following configure command :

    ./configure --enable-ipv6=no --build=powerpc-ibm-aix4.3.3.0 --host=powerpc-ibm-aix4.3.3.0

    It is important to use the --enable-ipv6=no option. If you don't do that the compilation won't work. This is a known problem with AIX (which is the PASE runtime). When the configuration step is over you can use the following 2 commands :

    make
    make install

    The first step will compile everything, and the second one will install everything in /usr/local (you must have created a symbolic link between /usr/local and /QOpenSys/usr/local).

  7. If you are on V5R1 and do not have the patch or make commands you can get the AIX binaries from the UCLA Public Domain Software Library for AIX at: http://aixpdslib.seas.ucla.edu
  8. Copy sqlcli.h , as400_libc.exp, and libdb400.exp from /QIBM/include/* to the phppkg folder
    • Enter command: CPY OBJ('/QIBM/include/sqlcli.h') TODIR('/QOpenSys/phppkg/') TOCCSID(*STDASCII) DTAFMT(*TEXT)
    You will find as400_libc.exp and libdb400.exp in the /QOpenSys/QIBM/ProdData/OS400/PASE/lib directory. After the copy of these files is done in the /QOpenSys/phppkg directory, make sure that you can read them with e.g. the DSPLNK command. These 3 files are in clear text so they should be human readable. If you cannot read them this is because you used the wrong parameter in the copy command. Another way to copy them is to do an ftp to the same machine the conversion will be handle properly.
  9. Set the CFLAGS, CC, and LDFLAGS environment variables by entering the 3 following commands. Make sure you change the export command to reflect where you placed the iSeries specific files.  Also add -O2 to the CFLAGS export to allow the compiler to perform optimization.  My export parameters looked like this:
    • export CFLAGS="-O2 -mcpu=powerpc -Wa,-many -DPASE -I /QOpenSys/phppkg/php-x.x.x"
    • export LDFLAGS='-Wl,-bI:/QOpenSys/phppkg/libdb400.exp,-bI:/QOpenSys/phppkg/as400_libc.exp'
    • export CC=gcc
  10. **These new instructions replace the "edit the makefile" instructions in the Redpaper
    You need to edit the configure file. Use the EDTF command in OS/400
    • EDTF "/QOpenSys/phppkg/php-4.3.x/configure"
    • Search for db2inst1 and change:
      ODBC_INCDIR=/home/db2inst1/sqllib/include
      to: ODBC_INCDIR=/QOpenSys/phppkg
      also change:
      ODBC_LIB DIR=/home/db2ins1/sqllib/lib
      to: ODBC_LIBDIR=/QOpenSys/phppkg
    • Search for -ldb2 and change
      ODBC_LIBS=-ldb2
      to: ODBC_LIBS=
  11. CD /QOpenSys/phppkg/php-x.x.x and run Configure
    ./configure --with-ibm-db2 --with-config-file-path=/QOpenSys/php/etc --prefix=/QOpenSys/php/ --enable-force-cgi-redirect --with-mysql --enable-inline-optimization --disable-debug --with-zlib --build=powerpc-ibm-aix5.1.0.0 --host=powerpc-ibm-aix5.1.0.0
  12. Be careful to the above command beccause this is through it that you can configure the PHP functions. So, most of the time the configuration process try to detect that the required function are already installed. For example, if you want to use the --with-mysql option, mysql must be installed previously. Of course, if you download one of the binary distribution that you will find on this website, you won't have this problem. However, in this case a call to the unknown function will crash PHP.

  13. When editing the makefile and the other files, do not use a Windows editor (such as Wordpad).  I used the OS/400 command EDTF.
     Note: Bryan Logan has informed me that you can use a Windows editor but you will need to modify the Makefile afterwords to strip out the carriage returns with the following commands:
        tr -d '\r' < Makefile > Makefile.new
        mv Makefile.new Makefile
  14. If make complains it can't find the Makefile, use the -f switch to identify the location of the Makefile.
    For example: make -f /QOpenSys/phppkg/php-4.3.0/Makefile Also, during the make process you will see some errors(ie. Function argument assignement between types xxx and yyy is not allowed) These errors are not fatal and AFAIK does not affect the product
  15. Edit the main/php_config.h file:
    • Delete #define HAVE_MMAP 1
    • Delete #define HAVE_SETITIMER 1
  16. Run the MAKE command:
    • make
    • make install
  17. cp php.ini-dist /QOpenSys/php/etc/php.ini
  18. Once PHP is installed and ready to go use the command: /QOpenSys/php/bin/php -v
    This  should display the version and confirm the install completed successfully.

Other Issues

Make sure you setup the folder and file permissions properly in the /QOpenSys/php/bin folder and on the php executable. The IBM Apache server uses the user profile: QTMHHTP1 when calling CGI applications unless you change the Server User Profile in the Apache config. Refer to the documentation in IBM iSeries Info Center.

*PUBLIC or user QTMHHTP1 will need to have read access to the QOpenSys folder, read access to the php folder, and read access to the bin folder. They will also need read and execute access to the php executable in the /QOpenSys/php/bin folder.

Make sure you have the latest PTFs for the PASE environment and for the HTTP server (powered by Apache). Go to http://www-919.ibm.com/developer/factory/pase/misc.html for info on the latest PASE ptfs.

The workaround for the PHP_SELF bug in the Redpaper may not need to be applied for 4.3.1 or 4.3.3 on V5R2. If you setup a simple test page like the sample below and run it you should be able to find the _SERVER["PHP_SELF"] variable and it's value should be the name of the page. (ie. /test.php)

<html>
< head>
< title>PHP Info Page</title>
< body>
< ?PHP
print phpinfo();
?>
< /body>
< /html>

Currently Net.Data and PHP cannot co-exist on the same web server instance without enforcing client authentication where Net.Data apps run under one user profile and PHP apps run under another user profile.  For more detail on this, visit the Net.Data forum: 
http://netdata.boulder.ibm.com/cgi-bin/db2www/forum.d2w/view?SID=20030609143529976001&NRL=3