umask 022

# dowload patch
cd /pool/files
wget http://janus.errornet.de/files/patches/apache2/apache2.0.40-php-cgi-suexec.diff

# unpack
cd /pool/build
tar xzvf /pool/files/httpd-2.0.43.tar.gz
tar xzvf /pool/files/php-4.2.3.tar.gz

# patch and build apache
cd httpd-2.0.43/support
patch < /pool/files/apache2.0.40-php-cgi-suexec.diff
sed 's,/usr/local/bin/php,/pool/system/php4/bin/php,' < suexec.h > suexec.tmp
mv suexec.tmp suexec.h
cd ..

MYPATH=/pool/system/apache2

"./configure" \
"--prefix=$MYPATH" \
"--enable-threads" \
"--with-perl=/usr/bin/perl" \
"--enable-so" \
"--enable-mods-shared=all cgid ext_filter bucketeer ssl proxy proxy-connect proxy-ftp proxy-http" \
"--enable-suexec" \
"--with-suexec-caller=www" \
"--with-suexec-uidmin=3000" \
"--with-suexec-gidmin=3000" \
"--with-suexec-userdir=public_html" \
"--with-suexec-docroot=/pool/www" \
"--with-suexec-safepath=/bin:/usr/bin:/usr/local/bin" \
"--with-suexec-logfile=$MYPATH/logs/suexec_log" \
"--with-suexec-bin=$MYPATH/bin/suexec"

make && make install
cd ..

# build php
cd php-4.2.3

MYPATH=/pool/system/php4

"./configure" \
"--prefix=$MYPATH" \
"--enable-safe-mode=no" \
"--enable-force-cgi-redirect=yes" \
"--enable-debug=no" \
"--with-config-file-path=$MYPATH/etc" \
"--enable-memory-limit" \
"--with-regex=system" \
"--with-gd=/usr" \
"--enable-gd-native-ttf" \
"--with-freetype-dir=/usr" \
"--with-jpeg-dir=/usr" \
"--with-png-dir=/usr" \
"--with-zlib" \
"--with-bz2=/usr" \
"--with-mysql=/usr" \
"--enable-ftp" \
"--enable-sockets" \
"--with-openssl" \
"--with-iconv" \
"--with-gettext" \
"--with-gdbm" \
"--enable-shmop" \
"--enable-memory-limit" \
"--enable-bcmath" \
"--enable-mhash" \
"--with-mcrypt" \
"--enable-track-vars" \
"--enable-calendar" \
"--with-snmp" \
"--enable-ucd-snmp-hack" \
"--enable-xslt" \
"--with-expat-dir=/usr" \
"--with-xslt-sablot=/usr" \
"--with-dom" \
"--with-dom-xslt" \
"--with-imap" \
"--with-imap-ssl"

make && make install


# setup php for apache
echo 'ScriptAlias /php4-cgi-bin-dir "/pool/system/php4/bin"' >> /pool/system/apache2/conf/httpd.conf
echo 'Action application/x-httpd-php /php4-cgi-bin-dir/php' >> /pool/system/apache2/conf/httpd.conf
echo 'AddHandler application/x-httpd-php .php' >> /pool/system/apache2/conf/httpd.conf

# test-info-file
echo '<? phpinfo(); ?>' > /pool/system/apache2/htdocs/info.php

