Rebuilding PHP RPM with Informix Support

 

 

For those of us out there still using the Informix database on Linux implementing a

dynamic webserver environment with Informix support has been difficult.  Up until now,

I have built and installed apache, PHP, gd, mod_perl, DBI, and DBD-Informix from

source.  This was a very long and tedious process (see my Apache/PHP/mod_perl/Informix

article for instructions) that produced the desired result, but upgrades and

maintenance were a pain. 

 

When I began building my RedHat 7.3 machine earlier this year, I made it a goal to keep

the machine as standard as possible.  My intention was to use RPM for everything in an

effort to avoid the pitfalls of custom compiled software.  Unfortunately, there was

one minor problem, the default PHP package is not compiled with Informix support. 

Hmmm....how does one rebuild and RPM with different options???   If you are like I was,

you have no idea. 

 

Thus began my quest to determine how to rebuild a package with different options. 

I spent a lot of time searching for seemingly non-existent documentation and even more

time experimenting with the hundreds of possible solutions before I came up with this

very simple solution.  Since this is the first time I have ever done this, it is likely

that I am not following many of the best-practices associated with RPM building.  If

you have a better or more appropriate method, just let me know and I will update this

document.

 

1. Install the Informix database and ESQL/C. (Write doc to cover Informix install procedure)

2. Set all environment variables (INFORMIXDIR, ONCONFIG, LD_LIBRARY_PATH) in

/etc/profile.  Mine look like this:

   A.  INFORMIXDIR=/usr/informix/current

   B.  ONCONFIG=onconfig.tcp0

   C.  LD_LIBRARY_PATH=/usr/informix/current/lib:/usr/informix/current/lib/esql:INFORMIXDIR/lib/cli:

3. Start Informix.  I have written a simple startup script located in /etc/init.d/Informix that accomplishes this with ease:

 

#!/bin/sh

#Set INFX_HOME to be equivalent to INFORMIX_HOME

#from which to execute oninit & onmode -k.

#Set INFX_OWNER to the user id of the owner of

#the Informix database in INFORMIX_HOME.

#

# chkconfig: 345 85 15

# description: informix database

# processorname: oninit

 

 

INFX_HOME=/usr/informix/current

INFX_OWNER=informix

 

if [ ! -f $INFX_HOME/bin/oninit ]

then

echo "Informix startup: cannot start"

exit

fi

 

case "$1" in

'start')

 

#Start the Informix databases:

#The following command assumes that the Informix

#login will not prompt for any values.

 

su - $INFX_OWNER -c "$INFX_HOME/bin/oninit" &

;;

 

'stop')

 

#Stop the Informix databases:

#The following command assumes that the Informix

#login will not prompt for any values.

 

su - $INFX_OWNER -c "$INFX_HOME/bin/onmode -ky" &

;;

esac

 

4. Create the stores7 sample database if you have no other database. 

5. Determine your current version of php using:  rpm -qa | grep php. (Is there a

better way?)

6. Install the php source RPM for your particular PHP version and machine architecture. 

I downloaded php-${version}.src.rpm from http://www.rpmfind.net and installed it using

"rpm -ivh php-${version}.src.rpm". 

7. Go to the /usr/src/redhat/SPECS directory.

10. Edit the php-${version}.spec file using your favorite editor.

9. Add the following entries:

           A.  LDFLAGS - Add the informix library paths to the LDFLAGS declaration similar to the following:  LDFLAGS="-L/usr/kerberos/lib -L/usr/informix/current/lib -L/usr/informix/current/lib/esql -L/usr/informix/current/lib/cli -L/usr/src/redhat/BUILD/php-${version}/build-cgi/ext/informix";export LDFLAGS

           B.  %configure - Add the " --with-informix=/usr/informix/current \" option to the configure command.  I dropped my entry right after the existing one for pgsql. 

           C.  Informix Libraries - Add the following lines below the apxs build root mess section:

           install -m 755 -d $RPM_BUILD_ROOT/usr/lib/informix

           install -m 755 /usr/informix/current/lib/esql/libifgen.so $RPM_BUILD_ROOT/usr/lib/informix

           install -m 755 /usr/informix/current/lib/esql/libifgls.so $RPM_BUILD_ROOT/usr/lib/informix

           install -m 755 /usr/informix/current/lib/esql/libifglx.so $RPM_BUILD_ROOT/usr/lib/informix

           install -m 755 /usr/informix/current/lib/esql/libifos.so $RPM_BUILD_ROOT/usr/lib/informix

           install -m 755 /usr/informix/current/lib/esql/libifsql.so $RPM_BUILD_ROOT/usr/lib/informix

           install -m 755 /usr/informix/current/lib/libifasf.so $RPM_BUILD_ROOT/usr/lib/informix

           D.  %files - Add the following lines to the bottom of the %files section:

                     %{_libdir}/informix/libifasf.so

                     %{_libdir}/informix/libifgen.so

                     %{_libdir}/informix/libifgls.so

                     %{_libdir}/informix/libifglx.so

                     %{_libdir}/informix/libifos.so

                     %{_libdir}/informix/libifsql.so

10. Save the changes.

10. Run the "rpmbuild -ba php-${version}.spec" command.

10. Wait a long time while it rebuilds the php package with your changes.

13. Go to the /usr/src/redhat/RPMS/i386 directory to find your newly built package.

14. Install the package over the existing one using the

"rpm -Uvh -force php-${version}.rpm" command.

15. Add the Informix environment variables to the /etc/init.d/apache startup script as in the below example:

 

#!/bin/bash

#

# Startup script for the Apache Web Server

#

# chkconfig: - 85 15

# description: Apache is a World Wide Web server.  It is used to serve \

#             HTML files and CGI.

# processname: httpd

# pidfile: /var/run/httpd.pid

# config: /etc/httpd/conf/access.conf

# config: /etc/httpd/conf/httpd.conf

# config: /etc/httpd/conf/srm.conf

 

# Source function library.

. /etc/rc.d/init.d/functions

 

# This will prevent initlog from swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS=""

 

# Path to the apachectl script, server binary, and short-form for messages.

apachectl=/usr/sbin/apachectl

httpd=/usr/sbin/httpd

prog=httpd

RETVAL=0

 

# Added environment variable for Informix as a test

export INFORMIXDIR=/usr/informix/current

export INFORMIXSERVER=duron_tcp0

export ONCONFIG=onconfig.tcp0

export PATH=$PATH:$INFORMIXDIR/bin

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql

 

# Find the installed modules and convert their names into arguments httpd

# can use.

moduleargs() {

       moduledir=/usr/lib/apache

       moduleargs=`

       /usr/bin/find ${moduledir} -type f -perm -0100 -name "*.so" | env -i tr '[:lower:]' '[:upper:]' | awk '{\

       gsub(/.*\//,"");\

       gsub(/^MOD_/,"");\

       gsub(/^LIB/,"");\

       gsub(/\.SO$/,"");\

       print "-DHAVE_" $0}'`

       echo ${moduleargs}

}

 

# The semantics of these two functions differ from the way apachectl does

# things -- attempting to start while running is a failure, and shutdown

# when not running is also a failure.  So we just do it the way init scripts

# are expected to behave here.

start() {

        echo -n $"Starting $prog: "

        daemon $httpd `moduleargs` $OPTIONS

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd

        return $RETVAL

}

stop() {

       echo -n $"Stopping $prog: "

       killproc $httpd

       RETVAL=$?

       echo

       [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid

}

reload() {

       echo -n $"Reloading $prog: "

       killproc $httpd -HUP

       RETVAL=$?

       echo

}

 

# See how we were called.

case "$1" in

  start)

       start

       ;;

  stop)

       stop

       ;;

  status)

        status $httpd

       RETVAL=$?

       ;;

  restart)

       stop

       start

       ;;

  condrestart)

       if [ -f /var/run/httpd.pid ] ; then

              stop

              start

       fi

       ;;

  reload)

        reload

       ;;

  graceful|help|configtest)

       $apachectl $@

       RETVAL=$?

       ;;

  *)

       echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"

       exit 1

esac

 

exit $RETVAL

 

16. Execute the "service httpd restart" command to restart apache with informix support.