Skip to content

Instantly share code, notes, and snippets.

@gcamrit
Forked from gedex/phpb
Created December 29, 2015 10:16
Show Gist options
  • Save gcamrit/340f35c39e839554f0cd to your computer and use it in GitHub Desktop.
Save gcamrit/340f35c39e839554f0cd to your computer and use it in GitHub Desktop.
Build multiple PHP versions
#!/bin/bash
#
# Build multiple PHP versions. Inspired by
# http://derickrethans.nl/multiple-php-version-setup.html
# This script assumes you have Git and build tols installed.
#
# Author: Akeda Bagus <admin@gedex.web.id>
# Licensed under MIT license.
# To reduce outgoing request, clone from
# local php-src repo which I cloned from
# http://git.php.net/repository/php-src.git
PHP_REPO="/home/repo/php-src"
CURRENT_DIR="$(pwd)"
# This is where all php versions will be built
TARGET_DIR="/home/lang/php/"
PHP_VERSION=$1
PHP_CLONE_CMD="git clone $PHP_REPO ."
PHP_CO_CMD="git checkout -b $PHP_VERSION tags/$PHP_VERSION"
# Adjust to your needs
BUILD_OPTIONS=" --enable-mbstring --with-bz2 --with-zlib
--enable-fpm --enable-fastcgi --without-pear \
--without-sqlite --without-sqlite3 --without-pdo-sqlite \
--with-gd --with-jpeg-dir=/usr"
usage() {
echo -e "Build multiple PHP version."
echo -e "Usage: $0 [arguments] [PHP_VERSION]\n"
echo -e "Examples:"
echo -e "Build php-5.4.3"
echo -e "\t $0 php-5.4.3\n"
echo -e "List of available PHP_VERSION"
echo -e "\t $0 list\n"
echo -e "[arguments]"
echo -e " help\t Display this help"
echo -e " list\t List of available PHP_VERSION"
}
php_version_list() {
cd $PHP_REPO
git tag -l | grep php-*
cd $CURRENT_DIR
exit 0
}
php_switch_to() {
PHP_VERSION=$2
}
php_build() {
# Set the prefix or taget build dir
TARGET_DIR=${TARGET_DIR}${PHP_VERSION}
mkdir -p ${TARGET_DIR}
cd ${TARGET_DIR}
# Get the source
$PHP_CLONE_CMD
$PHP_CO_CMD
# Build
make clean
rm -rf configure
./vcsclean
./buildconf --force
./configure --prefix=${TARGET_DIR} ${BUILD_OPTIONS}
make -j 5
make install
cd $CURRENT_DIR
exit 0
}
# If no args supplied
if [ $# -lt 1 ]
then
usage
exit 1
fi
if [[ $1 == "help" ]]
then
usage
exit 0
fi
if [[ $1 == "list" ]]
then
php_version_list
exit 0
fi
if [[ $1 == "switch" ]]
then
php_switch_to
fi
# Otherwise arg is PHP version switch into
for i in $(php_version_list); do
if [[ "$i" == "$PHP_VERSION" ]]
then
php_build
fi
done
echo -e "Unrecognized version $PHP_VERSION."
echo -e "Use $0 list to see list of available versions.\n"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment