Step by step what I did to compile it

  1. download PHP sources from www.php.net
  2. run configure script
    $ ./configure --enable-debug --enable-experimental-zts --disable-cgi
    [...]
    

    I added --disable-cgi else I could not make it to generate the CLI version.
    Edit: later it built the PHP SAPI module for Apache and the CLI version

    $ ./configure --with-apxs --enable-debug --enable-experimental-zts
    [...]
    Installing PHP SAPI module:       apache
    [activating module `php4' in /etc/apache/httpd.conf]
    cp libs/libphp4.so /usr/libexec/apache/libphp4.so
    chmod 755 /usr/libexec/apache/libphp4.so
    cp /etc/apache/httpd.conf /etc/apache/httpd.conf.bak
    cp /etc/apache/httpd.conf.new /etc/apache/httpd.conf
    rm /etc/apache/httpd.conf.new
    Installing PHP CLI binary:        /usr/local/bin/
    [...]
    
  3. compile PHP
    $ make
    [...]
    /usr/include/asm/errno.h:4:31: asm-generic/errno.h: No such file or directory
    [...]
    

    I didn't install the kernel headers and the configure script didn't notice. The asm-generic dir is in glibc-devel or, for Slackware it is only in 2.6 kernel headers such as kernel-headers-2.6.16.27-i386-1 so I need to install this package too.

  4. install PHP
    $ sudo make install
    Password:
    Installing PHP CLI binary:        /usr/local/bin/
    Installing PHP CLI man page:      /usr/local/man/man1/
    Installing PEAR environment:      /usr/local/lib/php/
    [PEAR] Archive_Tar: bad md5sum for file /usr/local/lib/php/Archive/Tar.php
    [PEAR] Console_Getopt: bad md5sum for file /usr/local/lib/php/Console/Getopt.php
    [PEAR] HTML_Template_IT: bad md5sum for file /usr/local/lib/php/HTML/Template/IT.php
    [PEAR] Net_UserAgent_Detect- installed: 2.0.1
    warning: pear/PEAR requires package "pear/Archive_Tar" (recommended version 1.3.1)
    warning: pear/PEAR requires package "pear/Console_Getopt" (recommended version 1.2)
    pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
    [PEAR] PEAR           - installed: 1.4.6
    Wrote PEAR system config file at: /usr/local/etc/pear.conf
    You may want to add: /usr/local/lib/php to your php.ini include_path
    [...]
    Installing build environment:     /usr/local/lib/php/build/
    Installing header files:          /usr/local/include/php/
    Installing helper programs:       /usr/local/bin/
      program: phpize
      program: php-config
    Installing man pages:             /usr/local/man/man1/
      page: phpize.1
      page: php-config.1
    
  5. quick check
    $ /usr/local/bin/php -v
    PHP 4.4.2 (cgi) (built: Jul 31 2006 23:03:26) (DEBUG)
    Copyright (c) 1997-2006 The PHP Group
    Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
    
  6. put example files from zend.com in a directory
    $ cd ext && mkdir hello && cd $_
    $ ls
    config.m4  hello.c  php_hello.h
    
  7. compile
    $ phpize
    Configuring for:
    PHP Api Version:         20020918
    Zend Module Api No:      20020429
    Zend Extension Api No:   20050606
    $ ./configure --enable-hello
    [...]
    $ make
    [...]
    $ sudo make install
    Password:
    Installing shared extensions:     /usr/local/lib/php/extensions/debug-zts-20020429/
    
  8. quick check (without editing php.ini)
    $ php -r 'dl("hello.so"); echo hello_world();'
    Hello World
    
  9. time needed to make (and correct ;-) a lot of mistakes: 1 hour 15 minutes...