Skip to content

Commit ca3703d

Browse files
committed
Allow running PIE for any PHP version
1 parent 8f84691 commit ca3703d

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

build.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,6 @@ cmd buildah run "$CONTAINER" -- \
326326
"/usr/local/bin/pie-latest" "99"
327327

328328
for PHP_MILESTONE in "${PHP_MILESTONES[@]}"; do
329-
case "$PHP_MILESTONE" in
330-
"5.6"|"7.0"|"7.1"|"7.2"|"7.3"|"7.4"|"8.0") continue ;;
331-
*) ;;
332-
esac
333-
334329
echo + "ln -s pie-php $(quote "…/usr/local/bin/pie-php$PHP_MILESTONE")" >&2
335330
ln -s pie-php "$MOUNT/usr/local/bin/pie-php$PHP_MILESTONE"
336331

@@ -339,13 +334,8 @@ for PHP_MILESTONE in "${PHP_MILESTONES[@]}"; do
339334
"/usr/local/bin/pie-php$PHP_MILESTONE" "${PHP_MILESTONE//./}"
340335
done
341336

342-
if [ -e "$MOUNT/usr/local/bin/pie-php$PHP_LATEST_MILESTONE" ]; then
343-
cmd buildah run "$CONTAINER" -- \
344-
update-alternatives --set pie "/usr/local/bin/pie-php$PHP_LATEST_MILESTONE"
345-
else
346-
cmd buildah run "$CONTAINER" -- \
347-
update-alternatives --auto pie
348-
fi
337+
cmd buildah run "$CONTAINER" -- \
338+
update-alternatives --set pie "/usr/local/bin/pie-php$PHP_LATEST_MILESTONE"
349339

350340
# install Composer
351341
php_composer_install "$CONTAINER" "latest-stable" "/usr/local/bin/composer-latest"

src/entrypoint.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ if [ "$1" == "php-fpm" ]; then
8585
[ ! -e "/etc/php/$PHP_MILESTONE/fpm/pool.d/www.conf" ] \
8686
|| update-alternatives --quiet --set php-fpm_www.sock "/run/php-fpm/$PHP_MILESTONE/php-fpm_www.sock"
8787

88-
[ -e "/usr/local/bin/pie-php$PHP_MILESTONE" ] \
89-
&& update-alternatives --quiet --set pie "/usr/local/bin/pie-php$PHP_MILESTONE" \
90-
|| update-alternatives --quiet --auto pie
88+
update-alternatives --quiet --set pie "/usr/local/bin/pie-php$PHP_MILESTONE"
9189
update-alternatives --quiet --set composer "/usr/local/bin/composer-php$PHP_MILESTONE"
9290
update-alternatives --quiet --set phive "/usr/local/bin/phive-php$PHP_MILESTONE"
9391
fi

src/usr/local/bin/pie-php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,38 @@
1212

1313
PHP="php"
1414
PIE="pie-latest"
15+
PIE_ARGS=()
1516

1617
if [[ "$(basename "$0")" =~ ^pie-(php[0-9]\.[0-9])$ ]]; then
1718
PHP="${BASH_REMATCH[1]}"
18-
# PIE never supported anything else than PHP 8.1+ only
19+
20+
case "$PHP" in
21+
"php5.6"|"php7.0"|"php7.1"|"php7.2"|"php7.3"|"php7.4"|"php8.0")
22+
# PIE itself must run with PHP 8.1 and later, but it can install extensions for any PHP version
23+
# in case of such old PHP version, run PIE with PHP 8.1 (earliest supported version)
24+
# and tell PIE what `php-config` and `phpize` binaries to use instead
25+
PHP_VERSION="${PHP:3}"
26+
27+
PHP_CONFIG="php-config$PHP_VERSION"
28+
PHP_CONFIG_PATH="$(type -P "$PHP_CONFIG" 2> /dev/null)"
29+
[ -n "$PHP_CONFIG_PATH" ] && [ -x "$PHP_CONFIG_PATH" ] \
30+
|| { echo "Invalid php-config executable \`$PHP_CONFIG\`: No such executable" >&2; exit 1; }
31+
32+
PHPIZE="phpize$PHP_VERSION"
33+
PHPIZE_PATH="$(type -P "$PHPIZE" 2> /dev/null)"
34+
[ -n "$PHPIZE_PATH" ] && [ -x "$PHPIZE_PATH" ] \
35+
|| { echo "Invalid phpize executable \`$PHPIZE\`: No such executable" >&2; exit 1; }
36+
37+
PIE_ARGS+=(
38+
--with-php-config="$PHP_CONFIG_PATH"
39+
--with-phpize-path="$PHPIZE_PATH"
40+
)
41+
42+
PHP="php8.1"
43+
;;
44+
45+
*) ;;
46+
esac
1947
fi
2048

2149
PHP_PATH="$(type -P "$PHP" 2> /dev/null)"
@@ -26,4 +54,4 @@ PIE_PATH="$(type -P "$PIE" 2> /dev/null)"
2654
[ -n "$PIE_PATH" ] && [ -x "$PIE_PATH" ] \
2755
|| { echo "Invalid PIE executable \`$PIE\`: No such executable" >&2; exit 1; }
2856

29-
exec "$PHP_PATH" -f "$PIE_PATH" -- "$@"
57+
exec "$PHP_PATH" -f "$PIE_PATH" -- "${PIE_ARGS[@]}" "$@"

0 commit comments

Comments
 (0)