Home

Building Apache & PHP on Linux RHEL 3 Print E-mail
User Rating: / 4
PoorBest 
Last Updated: Thursday, 21 December 2006

1. Introduction
     1.1. Modules & extensions
     1.2. Software dependencies
     1.3. Notational conventions
     1.4. Context
     1.5. Pre-requisite
     1.6. Environment
2. Building
     2.1. Creating the target structure
     2.2. Creating external links
     2.3. Embedding a private libgcc library (4.1.1)
     2.4. Compiling zlib (1.2.3)
     2.5. Compiling OpenSSL (0.9.7i)
     2.6. Compiling OpenLDAP (2.3.27 - 20060823)
     2.7. Compiling expat (2.0.0)
     2.8. Compiling libiconv (1.9.2)
     2.9. Compiling Apache (2.0.59)
     2.10. Compiling mod_jk (tomcat-connectors 1.2.18)
     2.11. Compiling libxml2 (2.6.26)
     2.12. Compiling libxslt (1.1.17)
     2.13. Compiling libpng (1.2.8-config)
     2.14. Compiling libjpeg (v6b)
     2.15. Compiling freetype (2.2.1)
     2.16. Compiling bzip2 (1.0.1)
     2.17. Compiling Curl (7.15.5)
     2.18. Compiling IMAP (4rev1)
     2.19. Compiling MySQL (5.0.24)
     2.20. Compiling PostgreSQL (8.1.4)
     2.21. Compiling mm (1.4.2)
     2.22. Compiling PHP 4 (4.4.4)
     2.23. Compiling PHP 5 (5.1.6)
3. Configuring
     3.1. System
     3.2. Apache
     3.3. Oracle client
     3.4. PHP
     3.5. Start & Stop scripts
4. Checking
     4.1. Starting Apache/PHP
     4.2. Checking the shared library dependencies
     4.3. Checking the PHP modules
5. Creating an RPM package
6. The end
7. Installing the package

Document history
V 1.0-1 JUN 2006 Creation
V 1.1-1 JUL 2006 Added mod_jk
Added imap
Added RPM creation on Linux
Suppressed AdoDB
V 1.2-1 SEP 2006 Component upgrade to the latest stable versions.
V1.4-4 SEP 2006 Added PHP 4
V 1.4-5 OCT 2006 Added Apache modules : isapi dumpio logio proxy proxy_connect proxy_ftp proxy_http.
Added the mm library (allows to store PHP session information in shmem).
V 1.4-9 NOV 2006 Minor bug corrections and optimizations

1 - Introduction

The goal here is to build a package including every libraries it depends on (except Oracle and system libraries). And everything must be located under a single directory tree.

1.1 - Modules & extensions

We are building Apache 2.0, PHP 4, and PHP 5 with the following modules and extensions :

  • Apache modules :
access actions alias asis auth auth_anon
auth_dbm auth_ldap autoindex cache case_filter case_filter_in
cern_meta cgi cgid charset_lite dav dav_fs
deflate dir disk_cache dumpio echo env
expires ext_filter file_cache headers imap include
info isapi jk (with jni) ldap log_config log_forensic
logio mem_cache mime mime_magic negotiation proxy
proxy_connect proxy_ftp proxy_http rewrite setenvif speling
status suexec ssl unique_id userdir usertrack
vhost_alias PHP 4 PHP 5      

:note These Apache modules are all compiled as shared objects (DSOs).

  • PHP 4 extensions :
bcmath bz2 calendar curl domxml ftp (with ssl)
gd (png, jpeg, freetype) iconv imap ldap mysql oci8
openssl pgsql sockets sysvmsg sysvsem sysvshm
xml zlib        
  • PHP 5 extensions :
bcmath bz2 calendar curl dom ftp (with ssl)
gd (png, jpeg, freetype) iconv imap ldap libxml mysql
mysqli oci8 openssl pdo pdo_mysql pdo_oci
pdo_pgsql pdo_sqlite pgsql shmop simplexml soap
sockets sqlite sysvmsg sysvsem sysvshm xml
xmlreader xmlwriter xsl zlib    

We also include the mm session handler support in PHP 4 & 5 (to be activated with the 'session_handler=mm' directive in php.ini)

1.2 - Software dependencies

The following diagram displays the dependencies between the software packages and libraries we are integrating together.

Sotware dependencies

:note We use the GD bundled library provided in the PHP source packages (4 & 5).

1.3 - Notational conventions

Everything written in red and between '<' and '>' characters must be manually adapted to your configuration.

Everything in black on grey can be copy/pasted as-is.

For instance :

dir=<$BASE>

means that you must replace the '<$BASE>' part with your base directory before typing the line, but :

dir=$BASE

must be entered as-is.

1.4 - Context

Host model : Dell Poweredge 6850
OS : Linux 2.4.21-37.ELsmp
RedHat release : Red Hat Enterprise Linux ES release 3 (Taroon Update 6)
Date : Sep 2006
Shell : /bin/bash
User : root (not mandatory)
Oracle client : 9.2.0

1.5 - Pre-requisite

Product Version
gcc 4.1.1
Gettext 0.11.4-7
Bison 1.875c-2.EL
Flex 2.5.4a-29
GNU make 3.79.1-17.1
pam-devel any
Java SDK 0.75

1.6 - Environment

First, we set the install directory :

export BASE=<your install directory>

We ensure that the LIBPATH, LD_LIBRARY_PATH, and SHLIB_PATH variables are not set. Only one is used on this system but it is easier to unset them all on every OS :

unset LIBPATH LD_LIBRARY_PATH SHLIB_PATH  || :

If your shell defines alias commands for cp, rm, or mv, you must unalias them now :

unalias cp rm mv || :

Here, we set the variables we use for every software and on every OS. Among others, we ensure that /usr/local/bin is in the PATH :

export BLIB=$BASE/libs
export PKG_CONFIG_PATH="$BLIB/pkg_common"

export CC=gcc
export MAKE=gmake
export CF_OPTS="--enable-shared --disable-static"
export PATH="$PATH:/usr/local/bin:/usr/ccs/bin"

We define where the external modules are located :

export ORACLE_HOME=<your Oracle home>
export JAVA_HOME=<your Java home>

We set the variables specific to this software :

export BAP=$BASE/apache

And we set the variables specific to this environment :

export CPPFLAGS="-I $BLIB/z/include -I $BLIB/ssl/include"

export LDFLAGS="-L$BLIB/common -Wl,-rpath,$BLIB/common"

And we save these values as reference values :

export REF_LDFLAGS="$LDFLAGS"
export REF_CPPFLAGS="$CPPFLAGS"

2 - Building

2.1 - Creating the target structure

[ -d $BLIB/common ] || mkdir -p $BLIB/common
[ -d $BLIB/pkg_common ] || mkdir -p $BLIB/pkg_common

Now, we create the script that we will use to create symbolic links from a common directory to every library file. This way, we can keep only this directory in the dynamic lib search path (LDFLAGS). We also create links to the pkgconfig files.

export LINKDIR=/tmp/linkdir
echo 'cd $BLIB/$1
cdir=$2
[ -z "$2" ] && cdir=common

for i in *
    do
    if [ -f "$i" ] ; then
        echo "Linking $i"
        /bin/rm -rf $BLIB/$cdir/$i
        ln -s ../$1/$i $BLIB/$cdir/$i
    fi
done

[ -d pkgconfig ] && $LINKDIR $1/pkgconfig pkg_common
exit 0
' >$LINKDIR
chmod +x $LINKDIR

2.2 - Creating external links

We use symbolic links for the external dependencies (Oracle & Java). This way, the path of the symbolic link is constant, and we can move the package anywhere, wherever Oracle and Java are physically installed.

ln -s $ORACLE_HOME $BLIB/oracle
ln -s $JAVA_HOME $BLIB/java

2.3 - Embedding a private libgcc library (4.1.1)

Some files we generate have a runtime dependency on the libgcc shared library file. This file belongs to gcc, which means that, by default, we should have libgcc installed on every runtime host ! Workaround : we include the libgcc shared library file in the final package, and we force the executable files to reference this copy :

mkdir -p $BLIB/gcc/lib
cp -p /usr/local/lib/libgcc_s.so* $BLIB/gcc/lib
$LINKDIR gcc/lib

:note If you don't have a shared gcc library on your system (as it happens with the gcc package from HP on HP-UX), the best solution is to rebuild gcc (gmake bootstrap builds the shared gcc lib we need).

2.4 - Compiling zlib (1.2.3)

Source : http://www.zlib.net/

./configure --shared --prefix=$BLIB/z

gmake "LDSHARED = gcc -shared $LDFLAGS"
gmake install

 #-- Cleanup

rm -rf $BLIB/z/share $BLIB/z/lib/*.a

$LINKDIR z/lib

2.5 - Compiling OpenSSL (0.9.7i)

Source : http://www.openssl.org/

:note As the configuration process does not use the LDFLAGS environment variable as it should, we have to modify several variables related to the way the libraries will be linked.

./config --openssldir=$BLIB/ssl shared zlib no-krb5

gmake "SHARED_LDFLAGS = -shared $LDFLAGS" \
    "EX_LIBS = $LDFLAGS -ldl -lz"

gmake install_sw

#-- Cleanup

rm -rf  $BLIB/ssl/man $BLIB/ssl/lib/*.a
$LINKDIR ssl/lib

gmake test "EX_LIBS = $LDFLAGS -ldl -lz"

2.6 - Compiling OpenLDAP (2.3.27 - 20060823)

Source : http://www.openldap.org/

#-- Need to specify OpenSSL location (no configure option)

CC=gcc \
    ./configure --prefix=$BLIB/ldap --without-cyrus-sasl \
    --disable-slapd --disable-slurpd --with-tls=openssl $CF_OPTS

gmake
gmake install

rm -rf $BLIB/ldap/bin $BLIB/ldap/man

$LINKDIR ldap/lib

2.7 - Compiling expat (2.0.0)

Source : http://expat.sourceforge.net/

./configure --prefix=$BLIB/expat $CF_OPTS

gmake
gmake install

#-- Cleanup

rm -rf $BLIB/expat/bin $BLIB/expat/man

$LINKDIR expat/lib

2.8 - Compiling libiconv (1.9.2)

Source : http://www.gnu.org/software/libiconv/

./configure --prefix=$BLIB/iconv $CF_OPTS

gmake
gmake install

rm -rf $BLIB/iconv/bin $BLIB/iconv/share/doc \
    $BLIB/iconv/share/man

$LINKDIR iconv/lib

2.9 - Compiling Apache (2.0.59)

Source : http://httpd.apache.org/ 

:note We compile Apache in 3 steps because our LDAP package is not in the standard location.

#-- Build apr

cd srclib/apr
./configure --prefix=$BAP --enable-threads $CF_OPTS

gmake
gmake install

#-- Build apr-util

cd ../apr-util
./configure --prefix=$BAP $CF_OPTS\
    --with-ldap \
    --with-ldap-lib=$BLIB/ldap/lib \
    --with-ldap-include=$BLIB/ldap/include \
    --with-iconv=$BLIB/iconv \
    --with-expat=$BLIB/expat \
    --with-apr=$BAP

gmake
gmake install

#-- Build Apache

cd ../..
./configure --prefix=$BAP \
    --enable-mods-shared="all cache case-filter case-filter-in cgid \
       charset-lite deflate disk-cache echo file-cache \
       mem-cache suexec ldap auth-ldap ssl isapi\
       dumpio logio proxy proxy_connect proxy_ftp proxy_http" \
    --disable-auth-digest \
    --with-perl=/usr/bin/perl \
    --with-z=$BLIB/z \
    --with-ssl=$BLIB/ssl \
    --with-iconv=$BLIB/iconv \
    --with-expat=$BLIB/expat \
    --with-apr=$BAP \
    --with-apr-util=$BAP\
         2>&1 | tee configure.log

gmake
gmake install
chown -Rh root:sys $BAP

chown -Rh root:sys $BAP

2.10 - Compiling mod_jk (tomcat-connectors 1.2.18)

Source : http://tomcat.apache.org/download-connectors.cgi

cd native

./configure --with-apxs=$BAP/bin/apxs \
    --with-java-home=$BLIB/java \
    --enable-jni

gmake
gmake install

cd ..

These command compile and install a mod_jk.so file in $BAP/modules.

2.11 - Compiling libxml2 (2.6.26)

Source : http://xmlsoft.org/

./configure --prefix=$BLIB/xml2 \
    --with-iconv=$BLIB/iconv \
    --with-zlib=$BLIB/z $CF_OPTS

gmake
gmake install

rm -rf $BLIB/xml2/man $BLIB/xml2/share $BLIB/xml2/bin/xmlcatalog \
    $BLIB/xml2/bin/xmllint $BLIB/xml2/lib/python2.2

$LINKDIR xml2/lib

2.12 - Compiling libxslt (1.1.17)

Source : http://xmlsoft.org/XSLT/

./configure --prefix=$BLIB/xslt \
    --with-libxml-prefix=$BLIB/xml2 $CF_OPTS

gmake
gmake install

/bin/rm -rf $BLIB/xslt/man $BLIB/xslt/share $BLIB/xslt/bin/xsltproc

$LINKDIR xslt/lib

2.13 - Compiling libpng (1.2.8-config)

Source : http://libpng.sourceforge.net/

./configure --prefix=$BLIB/png $CF_OPTS

gmake
gmake install

rm -rf $BLIB/png/man

$LINKDIR png/lib

2.14 - Compiling libjpeg (v6b)

Source : http://www.ijg.org/files

:note Here, the 'make install' process is unable to create the directories where the files must be installed. So, we create them by ourselves before installing.

./configure --prefix=$BLIB/jpeg $CF_OPTS

gmake
mkdir -p  $BLIB/jpeg/include $BLIB/jpeg/lib $BLIB/jpeg/bin \
    $BLIB/jpeg/man/man1
gmake install
sed -e "s/\(dlname=\)''/\1'libjpeg.so.62'/" \
    <libjpeg.la >$BLIB/jpeg/lib/libjpeg.la

rm -rf $BLIB/jpeg/bin $BLIB/jpeg/man

$LINKDIR jpeg/lib

2.15 - Compiling freetype (2.2.1)

Source : http://www.freetype.org/index2.html

:note On some OS, freetype seems to be incompatible with our version of zlib (don't know why it does not happen on every OS). Workaround: we systematically use the embedded zlib library.

#-- Build process needs GNU make (and a GNUMAKE variable)

GNUMAKE=gmake \
    ./configure --prefix=$BLIB/freetype --without-zlib $CF_OPTS

gmake
gmake install

$LINKDIR freetype/lib

2.16 - Compiling bzip2 (1.0.1)

Source : http://www.digistar.com/bzip2/

:note As the current makefile does not use our LDFLAGS settings, we must link the shared library with our own command.

:note We also must install the files manually as the Makefile is unable to do it.

#-- Build

gmake -f Makefile-libbz2_so
gcc -shared -o libbz2.so.1.0.1 $LDFLAGS *.o

#-- Install

mkdir -p $BLIB/bz2/include $BLIB/bz2/lib
cp bzlib.h $BLIB/bz2/include
cp libbz2.so.1.0.1 $BLIB/bz2/lib/libbz2.so.1.0.1
ln -s libbz2.so.1.0.1 $BLIB/bz2/lib/libbz2.so.1.0
ln -s  libbz2.so.1.0 $BLIB/bz2/lib/libbz2.so.1
ln -s libbz2.so.1 $BLIB/bz2/lib/libbz2.so

$LINKDIR bz2/lib

2.17 - Compiling Curl (7.15.5)

Source : http://curl.haxx.se/

./configure --prefix=$BLIB/curl \
    --with-zlib=$BLIB/z --with-ssl=$BLIB/ssl $CF_OPTS

gmake
gmake install

rm -rf $BLIB/curl/share/man $BLIB/curl/bin/curl

$LINKDIR curl/lib

2.18 - Compiling IMAP (4rev1)

Source : http://www.imap.org

:note The IMAP distribution does not provide a way to build a shared client library. So, we do it our way : we build the static library first, with the '-fPIC' compile flag to generate relocatable objects, and, then, we build the shared library from these objects.

:note We need a libc-client.a file in $BLIB/imap/lib because the PHP configure process specifically tests for the presence of this file. So, we create it as a symbolic link.

#-- Modify the Makefiles for SSL location

sed "s!/usr/local/ssl!$BLIB/ssl!g" <src/osdep/unix/Makefile >tmp1
cp tmp1 src/osdep/unix/Makefile

sed -e "s,/usr/include/openssl,$BLIB/ssl/include,g" \
    -e "s,/usr/share/ssl,$BLIB/ssl,g" \
    -e "s,SSLLIB=/usr/lib,SSLLIB=$BLIB/ssl/lib,g" <Makefile >tmp1
cp tmp1  Makefile

#-- Build a static library

gmake lrh "MAKE = gmake" "EXTRACFLAGS = -fPIC" \
    "EXTRASPECIALS = CC=gcc"

#-- Build the dynamic one

cd c-client
gcc  -shared -o libc-client.so *.o $LDFLAGS -lssl -lcrypto -ldl -lz

#-- Install the headers and the library
#-- PHP configure needs a '.a' file

mkdir -p $BLIB/imap/lib $BLIB/imap/include
cp libc-client.so $BLIB/imap/lib
ln -s libc-client.so $BLIB/imap/lib/libc-client.a
cp *.h $BLIB/imap/include

cd ..

$LINKDIR imap/lib

2.19 - Compiling MySQL (5.0.24)

Source : http://www.mysql.com/

:note Because of bug #21327, we have to modify the configure script before running it if we want to use OpenSSL from a non-standard location. This bug is supposed to be fixed in version 5.0.25. Here is a quick and dirty hack to fix it until then :

sed -e 's!\$d/libssl!$libs/libssl!g' <configure >configure.new
cp configure.new configure
chmod +x configure

CXX=gcc \
    ./configure --prefix=$BLIB/mysql $CF_OPTS \
    --enable-thread-safe-client \
    --with-zlib-dir=$BLIB/z \
    --with-openssl=$BLIB/ssl \
    --without-debug \
    --without-server \
    --without-extra-tools \
    --without-docs \
    --without-man \
    --without-bench 2>&1 | tee configure.log

gmake
gmake install

#-- Cleanup

rm -rf $BLIB/mysql/bin/* $BLIB/mysql/libexec $BLIB/mysql/mysql-test
cp scripts/mysql_config $BLIB/mysql/bin

#-- Remove server libraries

for i in dbug heap myisam myisammrg mystrings mysys vio
    do rm -f $BLIB/mysql/lib/mysql/lib$i.*
done

$LINKDIR mysql/lib/mysql

2.20 - Compiling PostgreSQL (8.1.4)

Source : http://www.postgresql.org/

The configure process does not use CPPFLAGS and LDFLAGS correctly (the problem only appears when the libraries are not installed in the usual locations). As a workaround, we feed it with modified values for some other environment variables.

LDFLAGS_SL="$LDFLAGS" \
    CFLAGS="$CPPFLAGS" \
    CPP="gcc -E $CPPFLAGS" \
    ./configure --prefix=$BLIB/pgsql $CF_OPTS \
    --without-docdir \
    --without-tcl \
    --with-openssl \
    --without-readline \
    --with-zlib \
    --without-krb5

gmake
gmake install

#-- Cleanup

rm -rf $BLIB/pgsql/bin/* $BLIB/pgsql/man $BLIB/pgsql/include/server \
    $BLIB/pgsql/lib/*.a

cp src/bin/pg_config/pg_config $BLIB/pgsql/bin

$LINKDIR pgsql/lib

2.21 - Compiling mm (1.4.2)

Source : http://www.ossp.org/pkg/lib/mm/

:note Here, the Makefile does not use the LDFLAGS variable, but we absolutely need it to specify the library search path. So, we have to use an ugly workaround... (Feature request #122 sent to the mm maintainers)

./configure --prefix=$BLIB/mm $CF_OPTS

gmake "libdir = $BLIB/mm/lib $LDFLAGS"
gmake install

rm -rf $BLIB/mm/share

$LINKDIR mm/lib

2.22 - Compiling PHP 4 (4.4.4)

Source : www.php.net

:note During installation, PHP inserts a 'LoadModule' line in httpd.conf. As we cannot have both PHP modules loaded at the same time, we decide that the default PHP module will be PHP 5. So, we comment out the PHP 4 LoadModule directive in the httpd.conf configuration file.

export PBASE=$BASE/php4

ORA_CF=''
if [ "$ORACLE_HOME" != 'none' ] ; then \
    if [ -d "$ORACLE_HOME/sdk" ] ; then    #-- InstantClient
        ORA_CF="--with-oci8-instant-client=shared,$BLIB/oracle"
    else    #-- Standard client
        ORA_CF="--with-oci8=shared,$BLIB/oracle"
    fi
fi

./configure --prefix=$PBASE \
    --with-config-file-path=$PBASE \
    --with-apxs2=$BAP/bin/apxs \
    --with-zlib=shared,$BLIB/z \
    --with-zlib-dir=$BLIB/z \
    --with-bz2=shared,$BLIB/bz2 \
    --enable-ftp=shared \
    --enable-dom \
    --with-iconv=shared,$BLIB/iconv \
    --with-iconv-dir=$BLIB/iconv \
    --enable-calendar=shared \
    --enable-sockets=shared \
    --enable-bcmath=shared \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-sysvmsg \
    --with-openssl=shared,$BLIB/ssl \
    --with-openssl-dir=$BLIB/ssl \
    --with-curl=shared,$BLIB/curl \
    --with-ldap=shared,$BLIB/ldap \
    --with-gd=shared \
    --with-png-dir=$BLIB/png \
    --with-jpeg-dir=$BLIB/jpeg \
    --enable-gd-native-ttf \
    --with-freetype-dir=$BLIB/freetype \
    --with-mysql=shared,$BLIB/mysql \
    --with-pgsql=shared,$BLIB/pgsql \
    --with-imap=shared,$BLIB/imap \
    --with-imap-ssl=$BLIB/ssl \
    --with-dom-xslt=$BLIB/xslt \
    --with-dom-exslt=$BLIB/xslt \
    --with-dom=$BLIB/xml2 \
    --with-expat-dir=$BLIB/expat \
    --with-mm=$BLIB/mm \
    $ORA_CF \
        2>&1 | tee configure.log

#-- Build & install

gmake
gmake install

#-- Comment out the LoadModule directive

sed 's/^LoadModule php4/#LoadModule php4/' <$BAP/conf/httpd.conf >tmp1
cp tmp1 $BAP/conf/httpd.conf

#-- Move extensions (personal, I don't like this 'no-debug...' dir)

cd $PBASE/lib/php/extensions
mv */* .
rmdir no-debug*
cd ~-

#-- Install default configuration file

cp php.ini-recommended $PBASE/php.ini

2.23 - Compiling PHP 5 (5.1.6)

Source : www.php.net

export PBASE=$BASE/php5

#-- Set Oracle configure options

ORA_CF=''
if [ "$ORACLE_HOME" != 'none' ] ; then \
    if [ -d "$ORACLE_HOME/sdk" ] ; then    #-- InstantClient
        ORA_CF="--with-oci8=shared,instantclient,$BLIB/oracle \
            --with-pdo-oci=shared,instantclient,$BLIB/oracle,10.2"
    else    #-- Standard client
        ORA_CF="--with-oci8=shared,$BLIB/oracle \
            --with-pdo-oci=shared,$BLIB/oracle"
    fi
fi
#-- Undocumented option - disables Oracle support in PHP5
#-- (and keeps it enabled for PHP4). Use if you want to compile PHP4 against
#-- a pre-9.0 version of Oracle (which is not supported by PHP5).

[ -n "$DISABLE_PHP5_ORA" ] && ORA_CF=''

./configure --prefix=$PBASE \
    --with-config-file-path=$PBASE \
    --with-apxs2=$BAP/bin/apxs \
    --with-zlib=shared,$BLIB/z \
    --with-zlib-dir=$BLIB/z \
    --with-bz2=shared,$BLIB/bz2 \
    --enable-ftp=shared \
    --with-libxml=$BLIB/xml2 \
    --with-xml=$BLIB/xml2 \
    --with-libxml-dir=$BLIB/xml2 \
    --with-xsl=shared,$BLIB/xslt \
    --enable-dom \
    --enable-simplexml \
    --with-iconv=shared,$BLIB/iconv \
    --with-iconv-dir=$BLIB/iconv \
    --enable-calendar=shared \
    --enable-sockets=shared \
    --enable-soap=shared \
    --enable-bcmath=shared \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-shmop \
    --enable-sysvmsg \
    --enable-pdo=shared \
    --with-pdo-sqlite=shared \
    --with-sqlite=shared \
    --enable-sqlite-utf8 \
    --with-openssl=shared,$BLIB/ssl \
    --with-openssl-dir=$BLIB/ssl \
    --with-curl=shared,$BLIB/curl \
    --with-ldap=shared,$BLIB/ldap \
    --with-gd=shared \
    --with-png-dir=$BLIB/png \
    --with-jpeg-dir=$BLIB/jpeg \
    --enable-gd-native-ttf \
    --with-freetype-dir=$BLIB/freetype \
    --with-mysql=shared,$BLIB/mysql \
    --with-mysqli=shared,$BLIB/mysql/bin/mysql_config \
    --with-pdo-mysql=shared,$BLIB/mysql \
    --with-pgsql=shared,$BLIB/pgsql \
    --with-pdo-pgsql=shared,$BLIB/pgsql \
    --with-imap=shared,$BLIB/imap \
    --with-imap-ssl=$BLIB/ssl \
    --with-mm=$BLIB/mm \
    $ORA_CF \
        2>&1 | tee configure.log

#-- Build

gmake
gmake install

#-- Move extensions (personal, I don't like this 'no-debug...' dir)

cd $PBASE/lib/php/extensions
mv */* .
rmdir no-debug*
cd ~-

#-- Install default configuration file

cp php.ini-recommended $PBASE/php.ini

3 - Configuring

Here, we give only a minimal configuration, which allows to start Apache/PHP, and to run the test we give below. When the package is installed on a target machine, it must be configured in a much more serious way. But this aspect is beyond the scope of this document.

:call

Warning : Running this package with the default configuration in a production environment can lead to serious performance and security problems !!
You have been warned

3.1 - System

  • Check that a www user exists in /etc/passwd. If not, create it with passwd='*' and login shell = /bin/false.
  • Add a www group in /etc/group if it does not already exist.

3.2 - Apache

Edit $BAP/conf/httpd.conf :

  • Change the line starting with 'User' to 'User www'
  • Change the line containing 'Group #-1' to 'Group www'.
  • Add this line anywhere in the file :

AddType application/x-httpd-php .php

Add the following line at the end of $BAP/bin/envvars :

unset LD_LIBRARY_PATH LIBPATH SHLIB_PATH

3.3 - Oracle client

Edit the file '$BAP/bin/envvars' and add the environment variables needed by the Oracle client :

ORACLE_HOME=<$BASE>/libs/oracle
export ORACLE_HOME

#-- TNS_ADMIN is optional, set only if you don't use the default
#-- location ($ORACLE_HOME/network/admin)

TNS_ADMIN=<directory>
export TNS_ADMIN

3.4 - PHP

For each PHP version, edit $BASE/php{4,5}/php.ini :

extension_dir = "<$BASE>/php/lib/php/extensions"

3.5 - Start & Stop scripts

cd $BASE
mkdir system
cd system

Create a file named apache in this directory. Its mode is 755 and it contains the following code :

# Apache/PHP start/stop script
#
# chkconfig: 2345 99 05
# description: Apache/PHP Web server
#
# V 1.3 (29-AUG-2006)
#
#============================================================================

export APACHE_HOME=<$BASE>

export PATH=/usr/sbin:/usr/bin:/sbin:$PATH

case $1 in
'start_msg') echo "Starting Apache Web Server";;
'stop_msg') echo "Stopping Apache Web Server";;

'start')
    # Check to see if apache is allowed to start...
    $APACHE_HOME/apache/bin/apachectl start && exit 0
    echo "** ERROR: Could not start Apache"
    exit 1
    ;;
   
'stop')
    $APACHE_HOME/apache/bin/apachectl stop >/dev/null 2>&1
    exit 0
    ;;
   
*)
    echo "usage: $0 {start|stop|start_msg|stop_msg}"
    exit 1
    ;;
esac

#============================================================================

4 - Checking

4.1 - Starting Apache/PHP

Now, start Apache with :

<$BASE>/system/apache start

This should not display any message.

4.2 - Checking the shared library dependencies

unset LIBPATH SHLIB_PATH LD_LIBRARY_PATH
cd $BASE
for i in `find . -type f` ; do
   ldd $i 2>/dev/null
done | grep -v 'not a dynamic ' \
    | sed -e 's/(.*)$//' -e 's,^.*> /,/,' -e 's, $,,g' -e 's,\.so[.0-9]*$,,' \
    | grep -v '/libwtc9$' \
    | sort -u \
    | grep -v "^$BASE/"

This script must display only the following system libraries :

  • /lib/ld-linux
  • /lib/libcrypt
  • /lib/libdl
  • /lib/liblaus
  • /lib/libnsl
  • /lib/libpam
  • /lib/libresolv
  • /lib/tls/libc
  • /lib/tls/libm
  • /lib/tls/libpthread
  • /lib/tls/librt

4.3 - Checking the PHP modules

Here, we just check that the PHP shared modules can be loaded without error. This check should be done every time you install your package to a new host, as it allows to check that every shared lib dependencies are satisfied.

The syntax of this script must be compatible with PHP versions 4 & 5. That's why we cannot use scandir().

By default, you will be testing PHP 5. In order to test your PHP 4 installation, comment out the PHP5 line in $BAP/conf/httpd.conf, uncomment the PHP4 line, restart Apache, and reload the page from your browser.

Create a new file named $BAP/htdocs/test.php with the following content :

<?php
error_reporting(E_ALL);
ini_set('display_errors',true);

$libs=array();
$dir=opendir(ini_get('extension_dir'));
while ($lib=readdir($dir))
    {
    if (fnmatch('*.'.PHP_SHLIB_SUFFIX,$lib)) $libs[]=$lib;
    }

sort($libs);
foreach($libs as $lib)
    {
    echo "Loading module $lib ...<br>";
    dl($lib);
    }

phpinfo();
?>

From your browser, display this page (URL = http://<your_server>/test.php).

It displays the configuration of every PHP modules, static and dynamic. If there are some errors when trying to load a module, it will also display them.

5 - Creating an RPM package

Now, we are going to package everything into an RPM package file. Note that it is a binary RPM, not a source RPM.

First, you need the rpmbuild tool. Download and install it on your host.

Create a symbolic link in /etc/init.d :

ln -s $BASE/system/apache /etc/init.d/apache

Create a $BASE/apache.spec file. Here is a sample content for this file (shell code is given for Linux) :

Name: apache
Summary: Apache/PHP
Group: Applications/Internet
Version: <Version>
Release: <Release>
ExclusiveOs: Linux
Copyright: Apache license/PHP license
Source: none
URL: <your url>
Packager: <your name>
Requires: glibc
AutoReqProv: no
provides: apache
%description
Apache by <your name> - <date>

Versions :
- Apache 2.0.xx
- PHP 5.1.xx
- MySQL 5.0.xx
- PostgreSQL 8.xx.xx

Contains the following Apache modules : access actions alias asis auth auth_anon
auth_dbm auth_ldap autoindex cache case_filter case_filter_in cern_meta
cgi cgid charset_lite dav dav_fs deflate dir disk_cache echo env expires
ext_filter file_cache headers imap include info ldap log_config log_forensic
mem_cache mime mime_magic negotiation rewrite setenvif speling status
suexec ssl unique_id userdir usertrack vhost_alias PHP5 jk (jni)

Includes the following PHP extensions : dom libxml shmop simplexml sysvmsg
sysvsem sysvshm xml xmlreader xmlwriter bcmath bz2 calendar curl
ftp (with ssl) gd (png, jpeg, freetype) iconv imap ldap mysql mysqli
oci8 openssl pdo pdo_mysql pdo_oci pdo_pgsql pdo_sqlite pgsql soap
sockets sqlite xsl zlib

%pre
#======================= Pre-Install script =============

#-- Ensure Group www exists

grep '^www:' /etc/group >/dev/null 2>&1 || groupadd -g 20080 www

#-- Ensure User www exists

grep '^www:' /etc/passwd >/dev/null 2>&1 \
|| useradd -c 'Apache user' -g www -M -s /bin/false -u 20080 -d /none www >

%post
#====================== Post-Install script ===============

#-- Add Apache to rc.d system services

/sbin/chkconfig --add apache
/sbin/chkconfig apache off

%preun
#====================== Pre-Uninstall script ==============
#-- Stop Apache

/etc/init.d/apache stop

#-- Remove it from the system services

/sbin/chkconfig --del apache

#-- Remove the log files because they are not part of the package
#-- and they won't be removed by rpm

/bin/rm -rf <$BASE>/apache/logs/*

#============================ FILES =================
%files
<$BASE>
/etc/init.d/apache
%config <$BASE>/apache/conf
%config <$BASE>/php/php.ini

What does this mean ?

  • The first lines contain information about the packages's name, requirements, packager (you), and a description.
  • the pre-install script ensures that the www user & group exist. If it is not the case, they are created.
  • The post-install script registers Apache as a system service for automatic start and stop at bootup and shutdown time.
  • The pre-uninstall script will stop Apache, remove it from the automatic start/stop system, and remove the log files.
  • Then, we give the list of the files, with some of them being tagged as configuration files (see the rpm documentation for more information).

Now, build you package with this command :

rpmbuild -bb $BASE/apache.spec

This will create a file named apache-<Version>-<Release>.<arch>.rpm in /usr/src/redhat/RPMS/<arch>. This is your RPM package.

6 - The end

Congratulations !

You have built a complete Apache/PHP RPM package.

7 - Installing the package

This package can be installed, like every other RPM packages, with the rpm command (see man rpm). An example of such an installation command is :

rpm -Uvh ftp://myserver/mydirectory/apache-1.0-1.i386.rpm

You can then configure Apache and PHP ($BASE/apache/conf and $BASE/php{4,5}/php.ini).

When the configuration is done, you can switch the automatic start system on with the following command :

/sbin/chkconfig apache on

:love Enjoy !

:note After every installation, remember to check the shared lib dependencies and the correct loading of every PHP modules (see Checking above).

Comments
Consultant
Written by Krishnarao Nandipati on 2007-02-08 00:16:44 IP: 82.240.16.115
Hi,  
 
I am trying install LAMP environment on the Redhat Linux ES3. I am having lot of difficulties to get PHP5 and mysql5 working togetcher. I am getting memory faults when I run php scripts with mysql code in it.  
 
Finally I found this your nice document. Before I proceed, I have few questions.  
 
Note: I have the following environment - Redhat Linux - ES-3 with gcc version (gcc version 2.96 20000731) 
 
Do I really need to satisfy the pre-reqs you mentioned. I am having trouble finding gcc 4.1.1 for redhat ES3. 
 
Please help.  
 
Thank you 
 
Re: No, there is no strict requirement on the pre-req versions. These are just the versions the document was validated with. These versions are important to me because, through these documents, I try to provide exactly the same features on several OS, but I don't see any reason why this build would fail with gcc 2 or 3, especially on Linux. Please keep us informed of the results you get with these older versions. Regards.

Only registered users can write comments.
Please login or register.

Powered by AkoComment!


All site content is (C) F. Laupretre (wishlist) - Unauthorized reproduction forbidden without express written permission.
Joomla! is Free Software released under the GNU/GPL License. - Template design: JLM@joomlabox