PHP 5 install script/dev

From DreamHost
Revision as of 09:09, 5 October 2007 by Mousee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PHP5 Install Script

This version includes some advanced "dummy proof" error checking. It also allows for, to some degree, updating older custom installs if they exist.
Unfortunately it's quite long, so if you're able to find ways to shorten it by all means please do!
Mousee 09:08, 30 May 2007 (PDT)

php5install.sh

#!/bin/sh
set -e

# Version 0.6e, 2007-10-05
#
# - Updated 2007-09-19 by Chris Shymanik (chris@chipsncheese.com)
#   - Updated to the latest PHP5 (5.2.4) and verified that it works.
#   - Updates to depedencies:
#         Curl (7.16.2 -> 7.17.0), freetype (2.3.4 -> 2.3.5), libxslt (1.1.20 -> 1.1.22)
#   - Minor revision 0.6d to fix an end-of-install bug.
# - Updated 2007-06-08 by Chris Shymanik (chris@chipsncheese.com)
#   - Will backup and re-install any old php.ini's found (see notes in wiki about this).
#   - Source file detection.
#   - Allows cgi-bin to be installed in a sub-directory (EXTDIR)
#   - Created steps as functions, for easier troubleshooting/modification.
#   - Updated various packages and did some additional code cleanup.
#   - OSSP mm (Shared Memory Allocation) and bzip2 packages added.
#   - Changed which binary to use, based on the new location in PHP 5.2.3.
# - Updated 2007-01-15 by Charles Wiltgen (charles@wiltgen.net)
#   - Make "nicer" to help keep it from getting killed by DreamHost
#   - Make less verbose to keep signal-to-noise level high
# - Updated 2006-12-25 by Carl McDade (hiveminds.co.uk)
#   - Allow memory limit and freetype

function config_env()
{
#### User Configuration Options
## Domain & Directory Configuration
# Domain to install to
export DOMAIN="mydomain.tld"
# Temporary source directory
SRCDIR=${HOME}/source
# Download temporary DIST files to which directory?
DISTDIR=${HOME}/dist
# Delete contents of DISTDIR after installation? (Default: No)
DISTDEL="No"
# Backup your previous php.ini files to which directory (if any)?
# Please Note: You'll need to remove this directory manually if it's used.
# (!!You MUST use a trailing slash when specifying this directive!!)
BACKUPDIR=${HOME}/php5tmp
# Install PHP5 to which directory?
INSTALLDIR=${HOME}/php5
# Install PHP5's cgi-bin files to a directory besides home?
#    ie.: /home/username/mywebsite.com/sub/level/directory
EXTYESNO="No"
# Directory under home in which the cgi-bin files will be installed to
#    ie.: /sub/level/directory 
EXTDIR=main
# Nice Level for Processes. (Deprecated)
# Higher is nicer, lower is less nice and could get your install process killed!
NICE=19
}

## Program Version Configuration
# Don't touch unless you know what you're doing!
PHP5="php-5.2.4"
LIBICONV="libiconv-1.11"
LIBMCRYPT="libmcrypt-2.5.8"
LIBXML2="libxml2-2.6.28"
LIBXSLT="libxslt-1.1.22"
MHASH="mhash-0.9.9"
ZLIB="zlib-1.2.3"
BZIP2="bzip2-1.0.4"
CURL="curl-7.17.0"
LIBIDN="libidn-0.6.9"
CCLIENT="imap-2004g"
CCLIENT_DIR="imap-2004g"
FREETYPE="freetype-2.3.5"
MM="mm-1.4.0"

#### END User Configuration Options
config_env

#### Advanced PHP Features Options
# Don't touch unless you know what you're doing!

PHPFEATURES="--prefix=${INSTALLDIR} \
 --with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN} \
 --enable-fastcgi \
 --enable-force-cgi-redirect \
 --with-xml \
 --with-xmlrpc \
 --with-libxml-dir=${INSTALLDIR} \
 --with-freetype-dir=${INSTALLDIR} \
 --enable-soap \
 --with-openssl=/usr \
 --with-mhash=${INSTALLDIR} \
 --with-mcrypt=${INSTALLDIR} \
 --with-zlib-dir=${INSTALLDIR} \
 --with-bz2=${INSTALLDIR} \
 --with-jpeg-dir=/usr \
 --with-png-dir=/usr \
 --with-gd \
 --enable-gd-native-ttf \
 --enable-memory-limit \
 --with-mm=${INSTALLDIR} \
 --enable-ftp \
 --with-exif \
 --enable-exif \
 --enable-sockets \
 --enable-wddx \
 --with-iconv=${INSTALLDIR} \
 --enable-sqlite-utf8 \
 --enable-calendar \
 --with-curl=${INSTALLDIR} \
 --enable-mbstring \
 --enable-mbregex \
 --with-mysql=/usr \
 --with-mysqli \
 --without-pear \
 --with-gettext \
 --with-imap=${INSTALLDIR} \
 --with-imap-ssl=/usr"

#### END Advanced PHP Features Options

########## DO NOT MODIFY BELOW ##########
sleep 1s

## Function to check for an existing install.
function check_prepare()
{
# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH

# Indicate the time at which the install started.
echo "Installation commencing..." `date +%r`
echo ""

# Backup previous php.ini file(s) if exist.
if [ -d ${INSTALLDIR}/etc/php5 ]; then
		  echo "--- Backing up php.ini file..."
		  mkdir -p ${BACKUPDIR}
		  cp -R ${INSTALLDIR}/etc/php5/* ${BACKUPDIR}/
		  echo "Done."
else
		  echo "No php.ini will be backed-up during this update!"
fi
# Check for existing php5 install, kill any running processes from it, and remove.
#	Note: This is only for fast-cgi processes. This should probably be modified
#		to detect other custom php5 processes for a fully functional script.
if [ -d ${INSTALLDIR} ]
		  then
		  # Check for a running process
		  #	Note: This is only a very basic detect & kill system.
		  if [ "$(ps aux | grep -q php5.fcgi)" == "php5.fcgi" ]
		  then
			  while [ "$(ps aux | grep -q php5.fcgi)" == "php5.fcgi" ]
			  do
					 kill -9 php5.fcgi
					 sleep 5s
			  done
		  fi
		  echo "Install directory exists! Killing active processes and clearing it..."
		  rm -rf ${INSTALLDIR}
else
		  echo "Install directory check complete."
fi
# Remove the existing cgi-bin directory.
if [ -d ${HOME}/${DOMAIN}/cgi-bin ]; then
		  echo "cgi-bin directory exists! Clearing contents..."
		  rm -rf ${HOME}/${DOMAIN}/cgi-bin
else
		  echo "cgi-bin directory check complete."
fi
}

## Function to check for and setup the appropriate paths.
function chkproc_paths()
{
# Detect how many processors the system has (for more optimal compliation).
cores=2   # the number of cores/procs to use when building
if [ $cores -a $cores -gt 1 ]; then
		  j="-j$cores "
fi
		  OS=`uname -s`
if [ "Darwin" = $OS ]; then
		  sed=gnused
		  makefile=makefile.macosx
else
		  makefile=makefile.linux_x86_ppc_alpha
		  sed=sed
fi
for i in $sed wget; do
		  $i --version >/dev/null 2>&1
done

# Clear and/or create the source directory.
if [ -d ${SRCDIR} ]; then
		  echo "Source directory already exists! Cleaning it..."
		  rm -rf $SRCDIR/*
else
		  echo "Creating source directory..."
		  mkdir -p ${SRCDIR}
fi
# Create the dist files directory if it doesn't exist
# optionally cleaning it if it does exist already.
if [ -d ${DISTDIR} ]; then
	echo ""; echo "Distribution directory already exists!"; echo "Clean it?"
	if [ ${DISTDEL} == "Yes" ]
	then
		echo ""; echo "Yes!"; echo "Cleaning now..."; echo ""
		rm -rf $DISTDIR/*
	else
		echo ""; echo "No!"; echo "Leaving the distribution directory intact."; echo ""
	fi
else
		  echo "Creating distribution directory..."
		  mkdir -p ${DISTDIR}
fi
}

## Function to get the required source files.
##	Note: Some future checking is required to ensure the primary mirror
##		is valid and use an alternative mirror if not.
function wget_source()
{
set +e
cd ${DISTDIR}
# Wget options
WGETOPT="-t1 -T10 -w5 -q -c"

# Check if packages already exist and get packages the ones that don't.
if [ -a ${DISTDIR}/${PHP5}.tar.bz2 ]; then
		  echo "Skipping wget of ${PHP5}.tar.bz2"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${PHP5}.tar.bz2
		  # If primary mirror fails, use the alternative mirror.
		  if [ -a ${DISTDIR}/${PHP5}.tar.bz2 ]; then
			echo "Got ${PHP5}.tar.bz2"
		  else
			wget $WGETOPT http://us3.php.net/distributions/${PHP5}.tar.gz
			# Check to make sure the alternative mirror worked.
				if [ -a ${DISTDIR}/${PHP5}.tar.gz ]; then
					echo "Got ${PHP5}.tar.gz"
				else
					echo "Failed to get ${PHP5}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${LIBICONV}.tar.gz ]; then
		  echo "Skipping wget of ${LIBICONV}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${LIBICONV}.tar.gz
		  if [ -a ${DISTDIR}/${LIBICONV}.tar.gz ]; then
		  	echo "Got ${LIBICONV}.tar.gz"
		  else
		  	wget $WGETOPT http://mirrors.usc.edu/pub/gnu/libiconv/${LIBICONV}.tar.gz
				if [ -a ${DISTDIR}/${LIBICONV}.tar.gz ]; then
					echo "Got ${LIBICONV}.tar.gz"
				else
					echo "Failed to get ${LIBICONV}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${LIBMCRYPT}.tar.gz ]; then
		  echo "Skipping wget of ${LIBMCRYPT}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${LIBMCRYPT}.tar.gz
		  if [ -a ${DISTDIR}/${LIBMCRYPT}.tar.gz ]; then
			echo "Got ${LIBMCRYPT}.tar.gz"
		  else
		  	wget $WGETOPT http://umn.dl.sourceforge.net/sourceforge/mcrypt/${LIBMCRYPT}.tar.gz
				if [ -a ${DISTDIR}/${LIBMCRYPT}.tar.gz ]; then
					echo "Got ${LIBMCRYPT}.tar.gz"
				else
					echo "Failed to get ${LIBMCRYPT}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${LIBXML2}.tar.gz ]; then
		  echo "Skipping wget of ${LIBXML2}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${LIBXML2}.tar.gz
		  if [ -a ${DISTDIR}/${LIBXML2}.tar.gz ]; then
		  	echo "Got ${LIBXML2}.tar.gz"
		  else
		  	wget $WGETOPT ftp://xmlsoft.org/libxml2/${LIBXML2}.tar.gz
				if [ -a ${DISTDIR}/${LIBXML2}.tar.gz ]; then
					echo "Got ${LIBXML2}.tar.gz"
				else
					echo "Failed to get ${LIBXML2}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${LIBXSLT}.tar.gz ]; then
		  echo "Skipping wget of ${LIBXSLT}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${LIBXSLT}.tar.gz
		  if [ -a ${DISTDIR}/${LIBXSLT}.tar.gz ]; then
		  	echo "Got ${LIBXSLT}.tar.gz"
		  else
		  	wget $WGETOPT ftp://xmlsoft.org/libxml2/${LIBXSLT}.tar.gz
				if [ -a ${DISTDIR}/${LIBXSLT}.tar.gz ]; then
					echo "Got ${LIBXSLT}.tar.gz"
				else
					echo "Failed to get ${LIBXSLT}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${MHASH}.tar.gz ]; then
		  echo "Skipping wget of ${MHASH}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${MHASH}.tar.gz
		  if [ -a ${DISTDIR}/${MHASH}.tar.gz ]; then
		  	echo "Got ${MHASH}.tar.gz"
		  else
			wget $WGETOPT http://umn.dl.sourceforge.net/sourceforge/mhash/${MHASH}.tar.gz
				if [ -a ${DISTDIR}/${MHASH}.tar.gz ]; then
					echo "Got ${MHASH}.tar.gz"
				else
					echo "Failed to get ${MHASH}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${ZLIB}.tar.bz2 ]; then
		  echo "Skipping wget of ${ZLIB}.tar.bz2"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${ZLIB}.tar.bz2
		  if [ -a ${DISTDIR}/${ZLIB}.tar.bz2 ]; then
		  	echo "Got ${ZLIB}.tar.bz2"
		  else
			wget $WGETOPT http://www.zlib.net/${ZLIB}.tar.gz
				if [ -a ${DISTDIR}/${ZLIB}.tar.gz ]; then
					echo "Got ${ZLIB}.tar.gz"
				else
					echo "Failed to get ${ZLIB}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${BZIP2}.tar.gz ]; then
		  echo "Skipping wget of ${BZIP2}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${BZIP2}.tar.gz
		  if [ -a ${DISTDIR}/${BZIP2}.tar.gz ]; then
		  	echo "Got ${BZIP2}.tar.gz"
		  else
			wget $WGETOPT http://www.bzip.org/1.0.3/${BZIP2}.tar.gz
				if [ -a ${DISTDIR}/${BZIP2}.tar.gz ]; then
					echo "Got ${BZIP2}.tar.gz"
				else
					echo "Failed to get ${ZLIB}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${MM}.tar.gz ]; then
		  echo "Skipping wget of ${MM}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${MM}.tar.gz
		  if [ -a ${DISTDIR}/${MM}.tar.gz ]; then
		  	echo "Got ${MM}.tar.gz"
		  else
			wget $WGETOPT ftp://ftp.ossp.org/pkg/lib/mm/${MM}.tar.gz
				if [ -a ${DISTDIR}/${MM}.tar.gz ]; then
					echo "Got ${MM}.tar.gz"
				else
					echo "Failed to get ${MM}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${CURL}.tar.bz2 ]; then
		  echo "Skipping wget of ${CURL}.tar.bz2"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${CURL}.tar.bz2
		  if [ -a ${DISTDIR}/${CURL}.tar.bz2 ]; then
		  	echo "Got ${CURL}.tar.bz2"
		  else
			wget $WGETOPT http://curl.haxx.se/download/${CURL}.tar.gz
				if [ -a ${DISTDIR}/${CURL}.tar.gz ]; then
					echo "Got ${CURL}.tar.gz"
				else
					echo "Failed to get ${CURL}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${FREETYPE}.tar.bz2 ]; then
		  echo "Skipping wget of ${FREETYPE}.tar.bz2"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${FREETYPE}.tar.bz2
		  if [ -a ${DISTDIR}/${FREETYPE}.tar.bz2 ]; then
		  	echo "Got ${FREETYPE}.tar.bz2"
		  else
			wget $WGETOPT http://umn.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz
				if [ -a ${DISTDIR}/${FREETYPE}.tar.bz2 ]; then
					echo "Got ${FREETYPE}.tar.bz2"
				else
					echo "Failed to get ${CURL}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${LIBIDN}.tar.gz ]; then
		  echo "Skipping wget of ${LIBIDN}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${LIBIDN}.tar.gz
		  if [ -a ${DISTDIR}/${LIBIDN}.tar.gz ]; then
		  	echo "Got ${LIBIDN}.tar.gz"
		  else
			wget $WGETOPT ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz
				if [ -a ${DISTDIR}/${LIBIDN}.tar.gz ]; then
					echo "Got ${LIBIDN}.tar.gz"
				else
					echo "Failed to get ${CURL}.tar.gz. Aborting install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${CCLIENT}.tar.Z ]; then
		  echo "Skipping wget of ${CCLIENT}.tar.Z"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${CCLIENT}.tar.Z
		  if [ -a ${DISTDIR}/${CCLIENT}.tar.Z ]; then
		  	echo "Got ${CCLIENT}.tar.Z"
		  else
			wget $WGETOPT ftp://ftp.cac.washington.edu/imap/old/${CCLIENT}.tar.Z
				if [ -a ${DISTDIR}/${CCLIENT}.tar.Z ]; then
					echo "Got ${CCLIENT}.tar.Z"
				else
					echo "Failed to get ${CCLIENT}.tar.Z. Aborting install!"
					exit 0
				fi
		  fi
fi
set -e
}

## Function to extract all the source files into the source directory.
function extract_source()
{
cd ${SRCDIR}
echo "Extracting ${PHP5}..."
if [ -a ${DISTDIR}/${PHP5}.tar.bz2 ]; then
	tar xjf ${DISTDIR}/${PHP5}.tar.bz2 > /dev/null
else
	tar xzf ${DISTDIR}/${PHP5}.tar.gz > /dev/null
fi
echo "Done."
echo "Extracting ${LIBICONV}..."
tar xzf ${DISTDIR}/${LIBICONV}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${LIBMCRYPT}..."
tar xzf ${DISTDIR}/${LIBMCRYPT}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${LIBXML2}..."
tar xzf ${DISTDIR}/${LIBXML2}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${LIBXSLT}..."
tar xzf ${DISTDIR}/${LIBXSLT}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${MHASH}..."
tar xzf ${DISTDIR}/${MHASH}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${ZLIB}..."
if [ -a ${DISTDIR}/${ZLIB}.tar.bz2 ]; then
	tar xjf ${DISTDIR}/${ZLIB}.tar.bz2 > /dev/null
else
	tar xzf ${DISTDIR}/${ZLIB}.tar.gz > /dev/null
fi
echo "Done."
echo "Extracting ${BZIP2}..."
tar xzf ${DISTDIR}/${BZIP2}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${MM}..."
tar xzf ${DISTDIR}/${MM}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${CURL}..."
if [ -a ${DISTDIR}/${CURL}.tar.bz2 ]; then
	tar xjf ${DISTDIR}/${CURL}.tar.bz2 > /dev/null
else
	tar xzf ${DISTDIR}/${CURL}.tar.gz > /dev/null
fi
echo "Done."
echo "Extracting ${FREETYPE}..."
if [ -a ${DISTDIR}/${FREETYPE}.tar.bz2 ]; then
	tar xjf ${DISTDIR}/${FREETYPE}.tar.bz2 > /dev/null
else
	tar xzf ${DISTDIR}/${FREETYPE}.tar.gz > /dev/null
fi
echo "Done."
echo "Extracting ${LIBIDN}..."
tar xzf ${DISTDIR}/${LIBIDN}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${CCLIENT}..."
uncompress -cd ${DISTDIR}/${CCLIENT}.tar.Z |tar x
echo "Done."
}

## Function to compile and install the packages.
function configsrc_install()
{
echo --- Configuring PHP5 and dependencies...
cd ${SRCDIR}/${LIBICONV}
./configure --enable-extra-encodings --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd ${SRCDIR}/${LIBXML2}
./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd ${SRCDIR}/${LIBXSLT}
./configure --prefix=${INSTALLDIR} \
 --with-libxml-prefix=${INSTALLDIR} \
 --with-libxml-include-prefix=${INSTALLDIR}/include/ \
 --with-libxml-libs-prefix=${INSTALLDIR}/lib/
nice -n ${NICE} make
make install

cd ${SRCDIR}/${ZLIB}
./configure --shared --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd ${SRCDIR}/${BZIP2}
nice -n ${NICE} make
make install PREFIX=${INSTALLDIR}

cd ${SRCDIR}/${MM}
./configure --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install PREFIX=${INSTALLDIR}

cd ${SRCDIR}/${LIBMCRYPT}
./configure --disable-posix-threads --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd  ${SRCDIR}/${LIBMCRYPT}/libltdl
./configure --prefix=${INSTALLDIR} --enable-ltdl-install
nice -n ${NICE} make
make install

cd ${SRCDIR}/${MHASH}
./configure --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd ${SRCDIR}/${FREETYPE}
./configure --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd ${SRCDIR}/${LIBIDN}
./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd ${SRCDIR}/${CURL}
./configure --with-ssl=${INSTALLDIR} --with-zlib=${INSTALLDIR} \
  --with-libidn=${INSTALLDIR} --enable-ipv6 --enable-cookies \
  --enable-crypto-auth --prefix=${INSTALLDIR}
nice -n ${NICE} make
make install

cd ${SRCDIR}/${CCLIENT_DIR}
make ldb
cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a
cp c-client/*.h ${INSTALLDIR}/include

cd ${SRCDIR}/${PHP5}
./configure ${PHPFEATURES}
nice -n ${NICE} make
make install
}

## Function for post install actions.
function php_postinstall()
{
config_env

# Restore the old php.ini if available and rename the default.
if [ -d ${BACKUPDIR} ]; then
		  echo "Restoring old php.ini configuration"
		  cp -R ${BACKUPDIR}/* ${INSTALLDIR}/etc/php5/
		  mv ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini-dist
else
		  echo "No previous php.ini to restore."
		  mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN}
		  cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini
fi

if [ ${EXTYESNO} == "Yes" ]
then
		  if [ -d ${HOME}/${DOMAIN}/${EXTDIR}/cgi-bin ]
		  then
					 echo "cgi-bin directory exists! Doing nothing..."
		  else
					 mkdir -p ${HOME}/${DOMAIN}/${EXTDIR}/cgi-bin
					 chmod 0755 ${HOME}/${DOMAIN}/${EXTDIR}/cgi-bin
		  fi
else
		  if [ -d ${HOME}/${DOMAIN}/cgi-bin ]
		  then
					 echo "cgi-bin directory exists! Doing nothing..."
		  else
					 mkdir -p ${HOME}/${DOMAIN}/cgi-bin
					 chmod 0755 ${HOME}/${DOMAIN}/cgi-bin
		  fi
fi
if [ ${EXTYESNO} == "Yes" ]; then
		  cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/${EXTDIR}/cgi-bin/php.cgi
		  cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/${EXTDIR}/cgi-bin/php5.fcgi
else
		  cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/cgi-bin/php.cgi
		  cp ${INSTALLDIR}/bin/php-cgi ${HOME}/${DOMAIN}/cgi-bin/php5.fcgi
fi
echo "Striping debug info from cgi-bin files..."
strip --strip-all ${HOME}/${DOMAIN}/cgi-bin/php.cgi
strip --strip-all ${HOME}/${DOMAIN}/cgi-bin/php5.fcgi
}

## Function for post install cleanup.
function postinstall_cleanup()
{
sleep 2s
cd ${HOME} && clear
echo "Post-Install clean-up..."

rm -rf $SRCDIR
if [ ${DISTDEL} == "Yes" ]; then
	rm -rf $DISTDIR
elif [ ${DISTDEL} == "No" ]; then
	echo "Your DISTDIR will not be cleaned."
else
	echo "Unknown DISTDEL option! Preserving your DISTDIR by default."
fi
}

# Prepare the environemnt to install PHP5 & Extras
check_prepare
# Check to ensure the install paths are created and correct
chkproc_paths
# Wget the sources for extraction
wget_source
# Extract the sources
extract_source
# Configure the source code and Install it
configsrc_install
# Misc. PHP installation steps (Post Install)
php_postinstall
# Cleanup the environment of items we no longer need
postinstall_cleanup

## End of Install
# Tell the user we're done.
echo "Installation completed!" `date +%r`
echo ""
echo "Remember to edit your .htaccess file now!"

#EOF

Using CGI/FCGI through .htaccess

The following are just examples, but certainly may be modified or used in any way you'd like. Just append the snippet below to your .htccess file (Note: This ASSUMES you know what you're doing. Please use the discussion page if you have questions about editing your .htaccess file).

CGI Example

#Normal CGI
AddHandler cgi-script .cgi
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi

FCGI Example

#FastCGI
AddHandler fastcgi-script fcgi fcg fpl
AddHandler php5-fastcgi .php
Action php5-fastcgi /php5-wrapper.fcgi

You'll also need to create the php5-wrapper.fcgi (or dispatch.fcgi) script, which should look something to the following:

#!/bin/sh
export PHPRC=~/php5/etc/php5/mydomain.tld
export PHP_FCGI_CHILDREN=2
exec ~/mydomain.tld/cgi-bin/php5.fcgi

While it's recommended you place this file in the root of your domain (ie. /home/username/mydomain.tld/php5-wrapper.fcgi), you may place it anywhere under your domain, so long as your .htaccess is pointing to its location and it is executable (chmod +x).