-
-
Save gedex/4364206 to your computer and use it in GitHub Desktop.
Build multiple PHP versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]> | |
# 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
Build multiple PHP versions
HOWTO:
Put this into /usr/bin or anywhere depending on your distro
Edit the file:
Change
PHP_REPO
to location in which this script will clone the repo.In my case I clone http://git.php.net/repository/php-src.git into /home/repo/php-src
so the script wont make outgoing request.
Change
TARGET_DIR
(supplied to--prefix
) to location in which all PHP versions will reside.Optionally update
BUILD_OPTIONS
, see http://php.net/manual/en/configure.about.phpNow you can build multiple PHP with:
phpb 5.4.6
phpb 5.3.5
See
phpb list
to see list of available releases.TODO:
Added simple way to export the PATH of PHP version. This means switch between all installed version.
Meanwhile you can do Derick's way: