Skip to content

Instantly share code, notes, and snippets.

@jmikola
Last active January 4, 2022 22:50
Show Gist options
  • Save jmikola/8100855 to your computer and use it in GitHub Desktop.
Save jmikola/8100855 to your computer and use it in GitHub Desktop.
Build scripts for multiple PHP versions
make_php () {
# Directory for PHP git repo (for git-new-workdir)
phpsrcdir="/home/jmikola/workspace/php/php-src"
# Git branch for this build (for git-new-workdir)
phpbranch="PHP-$1"
# Where compiled builds should be installed
installdir="/home/jmikola/bin/php"
# Directory where PHP builds will be stored
buildsdir="/home/jmikola/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
# Additional config options
read -d '' configopts <<"EOF"
--enable-debug
--with-zlib
--enable-json
--enable-libxml
--enable-xml
--enable-dom
--enable-cgi
--enable-pcntl
--enable-posix
--enable-phar
--with-pear
--with-openssl
--enable-session
EOF
# Set the config paths
configopts="$configopts --with-config-file-path=$installdir/etc"
configopts="$configopts --with-config-file-scan-dir=$installdir/etc/conf.d"
# Set the target directory for installation
configopts="$configopts --prefix=$installdir/$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 $configopts
make all -j8 && make install
}
for i in 5.3 5.4 5.5; do
make_php $i
make_php $i zts
done
pe () {
buildname="php-$1"
bindir="$HOME/bin/php/$buildname/bin"
if [ -x "$bindir/php" ]; then
PATH="$bindir:$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 $bindir/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