hints on Apache 2 and PHP on AIX

Warning: I know almost nothing about PHP. I haven't verified that building PHP in the manner that I suggest results in a completely functional build of PHP.

Please review http://www.php.net/manual/en/install.apache2.php, which contains information on using PHP with Apache 2 on Linux. The document you are reading will attempt to describe any special AIX nuances you may encounter.

Prereqs

  • PHP 4.3.4 tarball from www.php.net
  • working Apache 2.0.48 installation (see this document for hints)
  • Note: The PHP folks don't recommend using PHP with Apache 2 at all on any platform. Some people believe that it is safe to use PHP with Apache 2 as long as you are using the prefork MPM with Apache 2. Your mileage may vary.

    Building PHP

    configure

    In this example, /home/trawick/2048gcc is where Apache is installed, /home/trawick/php434gcc is where I will install PHP, and I'm using gcc for the compiler.

    $ CC=gcc ./configure --prefix=/home/trawick/php434gcc \
    --with-apxs2=/home/trawick/2048gcc/bin/apxs
    

    make

    $ make
    

    make install

    make install failed for me. Instead, I manually copied the PHP DSO to the Apache modules directory:

    $ cp -p .libs/libphp4.so /home/trawick/2048gcc/modules/
    

    make sure the DSO will load

    Add this line to httpd.conf:

    LoadModule php4_module modules/libphp4.so
    

    then see if apachectl configtest still works.

    Configure Apache for a simple PHP test

    Add this line to httpd.conf:

    AddType application/x-httpd-php .php .phtml
    

    Create this simple PHP page as file phpinfo.php under your Apache htdocs directory:

    <html>
    <head>
    <title>PHPinfo</title>
    </head>
    <body bgcolor=#FFFFFF>
    <p><? phpinfo() ?></p>
    </body>
    </html>
    
  • Start apache
    % apachectl start
    
    Make sure Apache started and you didn't get any segfaults from a bad PHP build.
  • Load /phpinfo.php from your server

    If you get a nicely formatted table describing PHP settings, PHP is working. If you get the PHP source code back to the browser then the Apache configuration to invoke PHP for *.php files isn't working right.

    ancient info

    software levels used

    Apache

    I didn't use any official tarball. It is Apache code from CVS from approx. 20030201. I think Apache 2.0.43 and above should behave the same.

    PHP

    I downloaded php-4.3.0.tar.gz from one of the mirror sites found at php.net.

    compiler

    Because someone mentioned they were having trouble using gcc, this documention is oriented towards using gcc. My version of gcc is that in the IBM RPM of gcc: gcc-2.9.aix43.010414-5.

    OS

    I don't know that it matters as long as you have AIX >= 4.3.3 recent ML. I happen to be using AIX 5.2 for these tests.

    step-by-step

  • Build and install Apache 2. The only requirement I can think of is that you enable mod_so ("--enable-so") and that you're using libtool >= 1.4.2.
  • Unpack PHP
    % gzip -dc php-4.3.0.tar.gz | tar -xf-
    
  • Configure PHP
    % cd php-4.3.0
    % ./configure --prefix=/jeff/trawick/phpinst --with-apxs2=/jeff/trawick/apacheinst/bin/apxs
    
    (substitute your desired PHP install path for /jeff/trawick/phpinst and substitute your Apache install path for /jeff/trawick/apacheinst)
  • Edit Makefile in PHP root directory

    Note: Some of the lines in Makefile are too darn long for native vi. You may wish to use emacs instead.

    Replace

    EXTRA_LDFLAGS = -Wl,-bI:/jeff/trawick/apacheinst/bin/httpd.exp -avoid-version -module
    
    with
    EXTRA_LDFLAGS = -Wl,-brtl -Wl,-bI:/jeff/trawick/apacheinst/modules/httpd.exp -avoid-version -module -L/opt/freeware/GNUPro/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix43-010414/powerpc -lgcc
    
    Be sure to replace the path /opt/freeware/GNUPro/.../powerpc" with the path to libgcc.a on your system.

    This replacement for the definition of EXTRA_LDFLAGS fixes three problems:

    1. PHP's build specifies the wrong path for httpd.exp. It is in the modules directory, not the bin directory.
    2. PHP doesn't actually use Apache's apxs to link the PHP DSO, so it misses out on turning on run-time linking. That is what "-Wl,-brtl" does.
    3. gcc-generated code sometimes references symbols like __udivdi3 and __divdi3 which are resolved by linking to libgcc.a. That is what the -L and -l options above do. Maybe your gcc build takes care of this automatically? If you try without adding -L and -l and the PHP DSO fails to load, add -L and -l and try again.
  • Run make
    % make
    
  • Manually install

    PHP's "make install" doesn't work. PHP apparently builds the DSO just a bit different than apxs would have, and apxs (or rather its helper script instdso.sh) blows up.

    cp -p .libs/libphp4.so.0 ~/apacheinst/modules/
    
    (Replace ~/apacheinst with the path to your Apache installation.) If you see a message like this
    cp: /jeff/trawick/apacheinst/modules/libphp4.so.0: Cannot open or remove a file containing a running program.
    
    either switch to root and run /usr/sbin/slibclean or manually remove the old copy.
  • load PHP into Apache Add this line to httpd.conf:
    LoadModule php4_module modules/libphp4.so.0
    
  • Configure Apache for a simple PHP test Add these lines to httpd.conf:
    <Files *.php>
    SetOutputFilter PHP
    SetInputFilter PHP
    AcceptPathInfo On
    LimitRequestBody 5524288
    </Files>
    
    Create this simple PHP page as file phpinfo.php under your Apache htdocs directory:
    <html>
    <head>
    <title>PHPinfo</title>
    </head>
    <body bgcolor=#FFFFFF>
    <p><? phpinfo() ?></p>
    </body>
    </html>
    
  • Start apache
    % apachectl start
    
    Make sure Apache started and you didn't get any segfaults from a bad PHP build.
  • Load /phpinfo.php from your server

    If you get a nicely formatted table describing PHP settings, PHP is working. If you get the PHP source code back to the browser then the Apache configuration to invoke PHP for *.php files isn't working right.

    alternative step-by-step if you don't mind rebuilding configure via buildconf

    This way you don't have to hack up Makefile.
  • Apply the patch mentioned in the PHP bug report for this problem and run buildconf prior to configure.
  • To deal with including libgcc functions in the PHP DSO, invoke configure with a setting for EXTRA_LDFLAGS, like this:
    EXTRA_LDFLAGS="-L/opt/freeware/GNUPro/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix43-010414/powerpc -lgcc" ./configure --prefix=/jeff/trawick/phpinst --with-apxs2=/jeff/trawick/apacheinst/bin/apxs
    

    If you have problems

    PHP DSO won't load into Apache

    You may want to try my cantloaddso.pl script which can suggest potential problems. For example, before I figured out the libgcc.a trick described above it printed the following messages:
    % cantloaddso.pl ~/apacheinst/modules/libphp4.so.0 ~/apacheinst
    Your DSO should be able to resolve all ap_ symbols.
    If it won't load, perhaps it is due to one of these symbols:
      __udivdi3 __divdi3
    %