As of CentOS 5 you’ll get PHP 5 rpm binaries, if for some reason your old applications aren’t PHP5 compliant yet, this might cause you some difficulties.

Even though PHP4 has it’s EOL as of 31-12-2007, the needed security updates will be done until 2008-08-08. This in my opinion could be a reason to at least make it possible to run PHP4 on CentOS 5. I myself really recommend upgrading to PHP5, it’s just matter of time…

I’ll walk through the process of building PHP4, which is quite a pain (as with any PHP release). If for some reason you wouldn’t want to do it yourself, i’ll try to post the binaries along at some point.

Setting up your BUILD environment.

We first need to setup our local BUILD environment, i myself feel that you should never build as root. The next commands will setup a local build environment:

[CaliMonk@DYV001 ~]$ mkdir ~/build && cd ~/build
[CaliMonk@DYV001 build]$ cp -R /usr/src/redhat/ .

The following echo stores your build path in ~/.rpmmacros, which is used by rpmbuild.

echo "%_topdir $HOME/build/redhat" > ~/.rpmmacros

Installing build RPM’s

In order to build RPM’s there are some development RPM’s needed, the following yum command installs the required RPM’s.

$ sudo yum install rpm-build autoconf automake m4 gcc gcc-c++ bison flex

Installing the CentOS 4.x PHP 4 src.rpm

I never felt like reinventing the wheel, that’s why we’re going to build our PHP4 RPM based upon the CentOS 4.x PHP4 RPM.

$ wget ftp://ftp.pbone.net/mirror/ftp.centos.org/4.5/updates/SRPMS/php-4.3.9-3.22.9.src.rpm
$ rpm -ivh php-4.3.9-3.22.9.src.rpm

Altering the SPEC file

$ cd ~/build/redhat/SPECS/ 

$ perl -pi.orig -e 's|Requires: php |Requires: php4 |g;' php.spec
$ perl -pi.orig -e 's|Provides: php|Provides: php4|g;' php.spec 

$ cp php.spec php4-4.3.9-3.22.9_LAB1.spec
$ vi php4-4.3.9-3.22.9_LAB1.spec

Because CentOS 5 now has PHP 5 as ‘php’ we need to call PHP 4 ‘php4′. This means there are some changes needed in the SPEC file. The following needs to be manually changed in the SPEC file (the previous commands did most, but not all):

--- php.spec.orig       2007-12-31 00:00:56.000000000 +0100
+++ php4-4.3.9-3.22.9_LAB1.spec 2007-12-31 00:01:15.000000000 +0100
@@ -4,9 +4,9 @@
 %define with_mhash %{?_with_mhash:1}%{!?_with_mhash:0}
Summary: The PHP HTML-embedded scripting language. (PHP: Hypertext Preprocessor)
-Name: php
+Name: php4
 Version: 4.3.9
-Release: 3.22.9
+Release: 3.22.9_LAB1
 License: The PHP License
 Group: Development/Languages
 URL: http://www.php.net/
@@ -115,10 +115,11 @@
 BuildRequires: bzip2, fileutils, file >= 4.0, perl, libtool >= 1.4.3
 # only to get correct sig_bin in pear.conf
 BuildRequires: gnupg
-Obsoletes: php-dbg, mod_php, php3, phpfi, stronghold-php, php-openssl
+Obsoletes: php4-dbg, mod_php, php3, phpfi, stronghold-php, php4-openssl
 # Enforce Apache module ABI compatibility
 Requires: httpd-mmn = %(cat %{_includedir}/httpd/.mmn || echo missing-httpd-devel)
 Requires: php-pear, file >= 4.0
+Conflicts: php-apache

Before we can start building we need to install a lot of devel RPM’s, which are dependencies of PHP.

$ sudo yum install bzip2-devel curl-devel db4-devel expat-devel gmp-devel aspell-devel httpd-devel libjpeg-devel libpng-devel pam-devel openssl-devel zlib-devel pcre-devel krb5-devel libc-client-devel cyrus-sascl-devel openldap-devel mysql-devel postgresql-devel unixODBC-devel net-snmp-devel elfutils-devel libxslt-devel libxml2-devel ncurses-devel freetype-devel

Now that everything is done, we need to start our first build of PHP4 on CentOS 5!

$ rpmbuild -bb php4-4.3.9-3.22.9_LAB1.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.39227
+ umask 022
+ cd /home/CaliMonk/build/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/CaliMonk/build/redhat/BUILD
+ rm -rf php-4.3.9
+ /bin/gzip -dc /home/CaliMonk/build/redhat/SOURCES/php-4.3.9.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd php-4.3.9
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
<HUGE SNIP>
/home/CaliMonk/build/redhat/BUILD/php-4.3.9/ext/snmp/snmp.c: In function 'php_snmpv3':
/home/CaliMonk/build/redhat/BUILD/php-4.3.9/ext/snmp/snmp.c:935: warning: pointer targets in passing argument 2 of 'netsnmp_session_gen_sec_key' differ in signedness
make: *** [ext/snmp/snmp.lo] Error 1
make: *** Waiting for unfinished jobs....
error: Bad exit status from /var/tmp/rpm-tmp.18939 (%build)
RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.18939 (%build)

As you can see here, the initial build seems to fail on Net-SNMP. CentOS 5 uses Net-SNMP 5.3.1, while CentOS 4 uses Net-SNMP 5.1.2. A search reveals this PHP bug report.

So, we need to take the diff provided and add it as a patch to our spec file.

$ cd ~/build/redhat/SOURCES/
$ wget http://dev.gentoo.org/~robbat2/php4-netsnmp52-aes.diff
$ mv php4-netsnmp52-aes.diff php-4.3.9-netsnmp52-aes.patch 

$ cd ~/build/redhat/SPEC
$ vi  php4-4.3.9-3.22.9_LAB1.spec

Add the following to the SPEC:

# Net SNMP Patch
Patch124: php-4.3.9-netsnmp52-aes.patch

And further down:

%patch124 -p1 -b .netsnmp52-ae

Rebuild again:

$ rpmbuild -bb php4-4.3.9-3.22.9_LAB1.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.39227
+ umask 022
+ cd /home/CaliMonk/build/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/CaliMonk/build/redhat/BUILD
+ rm -rf php-4.3.9
+ /bin/gzip -dc /home/CaliMonk/build/redhat/SOURCES/php-4.3.9.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd php-4.3.9
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .

<HUGE SNIP>
/home/CaliMonk/build/redhat/BUILD/php-4.3.9/ext/xmlrpc/libxmlrpc/xml_element.c: In function 'xml_elem_free_non_recurse':
/home/CaliMonk/build/redhat/BUILD/php-4.3.9/ext/xmlrpc/libxmlrpc/xml_element.c:191: error: invalid lvalue in assignment
/home/CaliMonk/build/redhat/BUILD/php-4.3.9/ext/xmlrpc/libxmlrpc/xml_element.c: In function 'xml_elem_entity_escape':
/home/CaliMonk/build/redhat/BUILD/php-4.3.9/ext/xmlrpc/libxmlrpc/xml_element.c:316: warning: pointer targets in assignment differ in signedness
/home/CaliMonk/build/redhat/BUILD/php-4.3.9/ext/xmlrpc/libxmlrpc/xml_element.c:331: warning: pointer targets in assignment differ in signedness
make: *** [ext/xmlrpc/libxmlrpc/xml_element.lo] Error 1
make: *** Waiting for unfinished jobs....
error: Bad exit status from /var/tmp/rpm-tmp.60423 (%build)

This time we have libxmlrpc failing on us, a search reveals another PHP bug report explaining that libxmlrpc doesn’t compile properly on GCC 4 (which is used on CentOS 5)Unfortunately the patch provides is for PHP5, not PHP4 so we need to make our own patch. The following is based upon the PHP5 patch and can be used as a patch. I could basically copy 99%, the rest was done searching for my_free and changing 0 to NULL.

The files I patched are: simplestring.c, xml_element.c and xmlrpc_private.h.

diff -Bru php-4.3.9/ext/xmlrpc/libxmlrpc/simplestring.c php-4.3.9-patched/ext/xmlrpc/libxmlrpc/simplestring.c
--- php-4.3.9/ext/xmlrpc/libxmlrpc/simplestring.c       2003-12-16 22:00:35.000000000 +0100
+++ php-4.3.9-patched/ext/xmlrpc/libxmlrpc/simplestring.c       2007-12-31 00:40:19.000000000 +0100
@@ -85,7 +85,7 @@
 #include <string.h>
 #include "simplestring.h"
-#define my_free(thing)  if(thing) {free(thing); thing = 0;}
+#define my_free(thing)  if(thing) {free(thing); thing = NULL;}
/*----------------------**
 * Begin String Functions *
diff -Bru php-4.3.9/ext/xmlrpc/libxmlrpc/xml_element.c php-4.3.9-patched/ext/xmlrpc/libxmlrpc/xml_element.c
--- php-4.3.9/ext/xmlrpc/libxmlrpc/xml_element.c        2004-06-01 22:16:18.000000000 +0200
+++ php-4.3.9-patched/ext/xmlrpc/libxmlrpc/xml_element.c        2007-12-31 00:35:45.000000000 +0100
@@ -112,7 +112,7 @@
 #include "expat.h"
 #include "encodings.h"
-#define my_free(thing)  if(thing) {free(thing); thing = 0;}
+#define my_free(thing)  if(thing) {free(thing); thing = NULL;}
 #define XML_DECL_START                 "<?xml"
 #define XML_DECL_START_LEN             sizeof(XML_DECL_START) - 1
@@ -188,7 +188,11 @@
       Q_Destroy(&root->children);
       Q_Destroy(&root->attrs);
-      my_free((char*)root->name);
+//      my_free((char*)root->name);
+       if(root->name) {
+               free((char *)root->name);
+               root->name=NULL;
+       }
       simplestring_free(&root->text);
       my_free(root);
    }
diff -Bru php-4.3.9/ext/xmlrpc/libxmlrpc/xmlrpc_private.h php-4.3.9-patched/ext/xmlrpc/libxmlrpc/xmlrpc_private.h
--- php-4.3.9/ext/xmlrpc/libxmlrpc/xmlrpc_private.h     2002-07-05 06:43:53.000000000 +0200
+++ php-4.3.9-patched/ext/xmlrpc/libxmlrpc/xmlrpc_private.h     2007-12-31 00:41:50.000000000 +0100
@@ -166,7 +166,7 @@
 /*----------------------------------------------------------------------------
  * Macros  */
-#define my_free(thing)  if(thing) {free(thing); thing = 0;}
+#define my_free(thing)  if(thing) {free(thing); thing = NULL;}
 #ifdef __cplusplus

We’ll call the file php-4.3.9-xmlrpc_gcc4.patch and put it in ~/build/redhat/SOURCES. As we did before we need to add this file to our SPEC file as well:

$ vi  php4-4.3.9-3.22.9_LAB1.spec

Add the following to the SPEC:

# xmlrpc GCC4 Patch
Patch125: php-4.3.9-xmlrpc_gcc4.patch

And further down:

%patch125 -p1 -b .xmlrpc_gcc4

Rebuild again:

$ rpmbuild -bb php4-4.3.9-3.22.9_LAB1.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.39227
+ umask 022
+ cd /home/CaliMonk/build/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/CaliMonk/build/redhat/BUILD
+ rm -rf php-4.3.9
+ /bin/gzip -dc /home/CaliMonk/build/redhat/SOURCES/php-4.3.9.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd php-4.3.9
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
<BIG SNIP>
make: *** [sapi/apache2handler/php_functions.lo] Error 1
error: Bad exit status from /var/tmp/rpm-tmp.3208 (%build)

As you might have noticed, the configure of PHP as CGI worked fine and we’ve run into an issue with making PHP as a module. On CentOS 5 we currently have httpd 2.2 by default, CentOS 4.x has httpd 2.0. It’s failing on the configure –with-apxs2 which build PHP as a module for Apache 2.x (DSO), using apxs.

Unfortunately, at this time I’m not quite sure what the exact cause is but I have some alternative ideas on how to get it running. If anyone has additional feedback, it’s much appreciated. I’ll post a follow up as soon as i have more.

Come back for more soon!

UPDATE: I managed to build PHP4 RPM’s, see my follow up topic.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Furl
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati