Skip to content

Instantly share code, notes, and snippets.

@jmikola
Last active December 21, 2015 14:49
Show Gist options
  • Save jmikola/6322416 to your computer and use it in GitHub Desktop.
Save jmikola/6322416 to your computer and use it in GitHub Desktop.
Manage multiple PHP development versions
make_php () {
# Directory for PHP git repo (for git-new-workdir)
phpsrcdir="$HOME/workspace/php/php-src"
# Git branch for this build (for git-new-workdir)
phpbranch="PHP-$1"
# Directory where PHP builds will be stored
buildsdir="$HOME/workspace/php/builds"
# Directory name for the current PHP build
buildname="$phpbranch"
# Append ZTS to build directory if necessary
if [ -n "$2" ]; then
buildname="$buildname-zts"
fi
# Set the target directory for installation
configopts="--prefix=$HOME/bin/php/$buildname"
# Append ZTS config option if necessary
if [ -n "$2" ]; then
configopts="$configopts --enable-maintainer-zts"
fi
# PHP 5.3 requires autoconf<=2.59
if [ $i == "5.3" ]; then
# Available via: apt-get install autoconf2.59
export PHP_AUTOCONF="/usr/bin/autoconf2.59"
else
export PHP_AUTOCONF="/usr/bin/autoconf"
fi
# See: http://nuclearsquid.com/writings/git-new-workdir/
git-new-workdir $phpsrcdir $buildsdir/$buildname $phpbranch
cd $buildsdir/$buildname
./buildconf --force
./configure --disable-all --enable-debug $configopts
make all -j8 && make install
}
for i in 5.3 5.4 5.5; do
make_php $i
make_php $i zts
done
# Sourced from ~/.bashrc
p () {
buildname="PHP-$1"
binpath="$HOME/bin/php/$buildname/bin/"
if [ -x "$binpath/php" ]; then
PATH="$binpath:$PATH"
# Trim duplicate entries from PATH
PATH=`awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) printf("%s:",$i); }}' <<< $PATH`
else
echo "Can't find $binpath/php or it isn't executable"
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment