| 1 |
#!/bin/bash |
| 2 |
# This script helps switching among different version of curl and PHP. |
| 3 |
# |
| 4 |
# From what I tried, since php-build builds PHP with the --with-curl option, it's not possible to provide the curl.so |
| 5 |
# module in php.ini file: Module already loaded error. Any workaround failed. |
| 6 |
# The only solution I found was to build PHP from source without the --with-curl option and link the curl extension |
| 7 |
# afterwards. |
| 8 |
# Therefore, here are the exact steps this script follows: |
| 9 |
# |
| 10 |
# - Check that PHP binaries, libcurl and PHP curl extension (for this version of PHP and curl) are not cached already. |
| 11 |
# If so, we have nothing to do. |
| 12 |
# - Download curl (from curl official website) and PHP sources (from php/php-src repo). |
| 13 |
# - Build curl into /tmp/curl/curl/CURL_VERSION |
| 14 |
# - Build php-curl shared object (curl.so) into /tmp/curl/php-curl/PHP_VERSION/CURL_VERSION |
| 15 |
# - Download php-build and patch it to drop the --with-curl option. |
| 16 |
# - Build PHP into /tmp/curl/php/PHP_VERSION/ |
| 17 |
# - Update php.ini in /tmp/curl/php/PHP_VERISON/etc/php.ini to load curl module (that we previously build). |
| 18 |
|
| 19 |
set -x |
| 20 |
set -e |
| 21 |
|
| 22 |
if [ $# -lt 2 ]; then |
| 23 |
echo "Usage: $0 curl_version php_version" |
| 24 |
exit 1 |
| 25 |
fi |
| 26 |
|
| 27 |
CURL_VERSION="$1" |
| 28 |
PHP_VERSION="$2" |
| 29 |
ROOT_DIRECTORY="/tmp/curl" |
| 30 |
PHP_DIRECTORY="$ROOT_DIRECTORY/php/$PHP_VERSION" |
| 31 |
CURL_DIRECTORY="$ROOT_DIRECTORY/curl/$CURL_VERSION" |
| 32 |
PHP_CURL_DIRECTORY="$ROOT_DIRECTORY/php-curl/$PHP_VERSION/$CURL_VERSION" |
| 33 |
|
| 34 |
if [ -f "$PHP_CURL_DIRECTORY/curl.so" ] \ |
| 35 |
&& [ -f "$CURL_DIRECTORY/lib/libcurl.so" ] \ |
| 36 |
&& [ -d "$PHP_DIRECTORY/bin" ]; then |
| 37 |
echo "Curl shared objects were cached. Skipping." |
| 38 |
exit 0 |
| 39 |
fi |
| 40 |
|
| 41 |
SCRIPT_PATH="$(readlink --canonicalize-existing "$0")" |
| 42 |
DIR_PATH="$(dirname "$SCRIPT_PATH")" |
| 43 |
source "$DIR_PATH/travis_wait.sh" |
| 44 |
|
| 45 |
mkdir -p "$PHP_DIRECTORY" "$CURL_DIRECTORY" "$PHP_CURL_DIRECTORY" |
| 46 |
|
| 47 |
TEMP_DIRECTORY="$(mktemp -d)" |
| 48 |
|
| 49 |
cd "$TEMP_DIRECTORY" |
| 50 |
|
| 51 |
# Build curl |
| 52 |
if ! [ -f "$CURL_DIRECTORY/lib/libcurl.so" ]; then |
| 53 |
curl -L "https://curl.haxx.se/download/curl-$CURL_VERSION.tar.gz" --output curl.tar.gz |
| 54 |
tar -xzf curl.tar.gz |
| 55 |
cd "curl-$CURL_VERSION" |
| 56 |
|
| 57 |
./configure --prefix="$CURL_DIRECTORY" |
| 58 |
make |
| 59 |
make install |
| 60 |
|
| 61 |
cd .. |
| 62 |
fi |
| 63 |
# End build curl |
| 64 |
|
| 65 |
# Build PHP |
| 66 |
if ! [ -d "$PHP_DIRECTORY/bin" ]; then |
| 67 |
git clone https://github.com/php-build/php-build.git |
| 68 |
grep -v "with-curl" "php-build/share/php-build/default_configure_options" \ |
| 69 |
> "php-build/share/php-build/default_configure_options_" |
| 70 |
mv "php-build/share/php-build/default_configure_options_" "php-build/share/php-build/default_configure_options" |
| 71 |
travis_wait 30 php-build/bin/php-build "$PHP_VERSION" "$PHP_DIRECTORY" |
| 72 |
fi |
| 73 |
# End build PHP |
| 74 |
|
| 75 |
# Build PHP Curl |
| 76 |
if ! [ -f "$PHP_CURL_DIRECTORY/curl.so" ]; then |
| 77 |
curl -L "https://github.com/php/php-src/archive/php-$PHP_VERSION.tar.gz" --output php.tar.gz |
| 78 |
tar -xzf php.tar.gz |
| 79 |
|
| 80 |
cd "php-src-php-$PHP_VERSION/ext/curl/" |
| 81 |
chmod +x "$PHP_DIRECTORY/bin/phpize" |
| 82 |
"$PHP_DIRECTORY/bin/phpize" |
| 83 |
./configure --with-curl="$CURL_DIRECTORY" --with-php-config="$PHP_DIRECTORY/bin/php-config" |
| 84 |
make |
| 85 |
cp modules/* "$PHP_CURL_DIRECTORY" |
| 86 |
|
| 87 |
# Add PHP Curl module to php.ini if it's not already present |
| 88 |
EXTENSION_LINE="extension=$PHP_CURL_DIRECTORY/curl.so" |
| 89 |
PHP_INI_FILE="$PHP_DIRECTORY/etc/php.ini" |
| 90 |
sed -i '/extension=.*curl.so/d' "$PHP_INI_FILE" |
| 91 |
echo "$EXTENSION_LINE" >> "$PHP_INI_FILE" |
| 92 |
|
| 93 |
cd .. |
| 94 |
fi |
| 95 |
# End build PHP Curl |
| 96 |
|