#!/bin/sh

# THIS WILL INSTALL THE SPECIFIED VERSION OF PHP
# TO /usr/local/bin, etc. YOU WILL GET THE CGI/FASTCGI
# AND COMMAND LINE BINARIES. YOU WILL *NOT* GET mod_php,
# SO MAKE SURE YOU FOLLOW 
# http://punkave.com/window/2010/03/08/faster-php-kill-kill
# AFTER THIS

VERSION=$1

USAGE="Usage: update-php.sh [version]"

if [ -z "$1" ] ; then
  echo $USAGE
  exit 1
fi

rm -f php-$VERSION.tar.gz &&
wget --trust-server-names http://us3.php.net/get/php-$VERSION.tar.gz/from/us.php.net/mirror &&
tar -zxf php-$VERSION.tar.gz &&
cd php-$VERSION &&
# mod_php for Apache if we choose to use it. Also installs CLI
# ACHTUNG: Does NOT play nice with fastcgi/cgi on the same box once
# pecl extensions get involved ): 
#'./configure' '--with-apxs2=/usr/bin/apxs2' '--with-gd' '--with-pdo-mysql' '--with-curl' '--with-mysql' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-mcrypt' '--with-zlib' '--enable-mbstring' '--enable-ftp' '--with-xsl' '--with-openssl' '--with-kerberos' '--enable-exif' '--enable-intl' &&

# CGI (fastcgi) binary. Also installs CLI binary
'./configure' '--enable-fastcgi' '--with-gd' '--with-pdo-mysql' '--with-curl' '--with-mysql' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-mcrypt' '--with-zlib' '--enable-mbstring' '--enable-ftp' '--with-xsl' '--with-openssl' '--with-kerberos' '--enable-exif' '--enable-intl' &&
make clean &&
make &&
make install &&
pecl channel-update pecl.php.net &&
pecl config-set php_ini /usr/local/lib/php.ini &&

# pecl's conf settings for tmp folders don't cover all of its
# usages of /var/tmp. ): Make sure /var/tmp is executable for now
mount -o,remount,rw,exec /tmp &&

(printf "\n" | pecl install -f apc) &&
pecl install -f mongo

# Regardless of whether any of that failed make sure we
# put the tmp folder back to noexec
mount -o,remount,rw,noexec /tmp

