Skip to content

Commit 7ae907d

Browse files
authored
[php] - Install xdebug from source if installation fails with PECL (#1671)
1 parent 72df8a5 commit 7ae907d

4 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/php/devcontainer-feature.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "php",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"name": "PHP",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/php",
66
"options": {
@@ -9,8 +9,8 @@
99
"proposals": [
1010
"latest",
1111
"8",
12-
"8.2",
13-
"8.2.0",
12+
"8.5",
13+
"8.5.0",
1414
"none"
1515
],
1616
"default": "latest",

src/php/install.sh

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,31 @@ addcomposer() {
170170
"${PHP_SRC}" -r "unlink('composer-setup.php');"
171171
}
172172

173+
# Build xdebug from its official source tarball. Used as a fallback when
174+
# pecl.php.net is broken or has no release advertising compatibility with
175+
# the current PHP version (common around new PHP releases).
176+
install_xdebug_from_source() {
177+
XDEBUG_VERSION="latest"
178+
find_version_from_git_tags XDEBUG_VERSION https://github.com/xdebug/xdebug "tags/"
179+
180+
local xdebug_src_dir="/tmp/xdebug-src"
181+
rm -rf "${xdebug_src_dir}"
182+
mkdir -p "${xdebug_src_dir}"
183+
184+
wget -O /tmp/xdebug.tgz "https://xdebug.org/files/xdebug-${XDEBUG_VERSION}.tgz"
185+
tar -xzf /tmp/xdebug.tgz -C "${xdebug_src_dir}" --strip-components=1
186+
187+
(
188+
cd "${xdebug_src_dir}"
189+
"${PHP_INSTALL_DIR}/bin/phpize"
190+
./configure --enable-xdebug --with-php-config="${PHP_INSTALL_DIR}/bin/php-config"
191+
make -j "$(nproc)"
192+
make install
193+
)
194+
195+
rm -rf "${xdebug_src_dir}" /tmp/xdebug.tgz
196+
}
197+
173198
init_php_install() {
174199
PHP_INSTALL_DIR="${PHP_DIR}/${PHP_VERSION}"
175200
if [ -d "${PHP_INSTALL_DIR}" ]; then
@@ -219,8 +244,10 @@ install_php() {
219244

220245
# PHP 7.4+, the pecl/pear installers are officially deprecated and are removed in PHP 8+
221246
# Thus, requiring an explicit "--with-pear"
247+
OLDIFS=$IFS
222248
IFS="."
223249
read -a versions <<< "${PHP_VERSION}"
250+
IFS=$OLDIFS
224251
PHP_MAJOR_VERSION=${versions[0]}
225252
PHP_MINOR_VERSION=${versions[1]}
226253

@@ -240,8 +267,13 @@ install_php() {
240267
cp -v $PHP_SRC_DIR/php.ini-* "$PHP_INI_DIR/";
241268
cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
242269

243-
# Install xdebug
244-
"${PHP_INSTALL_DIR}/bin/pecl" install xdebug
270+
# Install xdebug. Try PECL first (fast path), then fall back to building
271+
# from source if PECL's channel cache is broken or no release advertises
272+
# compatibility with the current PHP version.
273+
"${PHP_INSTALL_DIR}/bin/pecl" channel-update pecl.php.net || true
274+
if ! "${PHP_INSTALL_DIR}/bin/pecl" install xdebug; then
275+
install_xdebug_from_source
276+
fi
245277
XDEBUG_INI="${CONF_DIR}/xdebug.ini"
246278

247279
echo "zend_extension=${PHP_EXT_DIR}/xdebug.so" > "${XDEBUG_INI}"

test/php/install_additional_php.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8-
check "php version 8.4.2 installed as default" php --version | grep 8.4.2
9-
check "php version 8.3.14 installed" ls -l /usr/local/php | grep 8.3.14
10-
check "php version 8.2.27 installed" ls -l /usr/local/php | grep 8.2.27
8+
check "php version 8.5.0 installed as default" php --version | grep 8.5.0
9+
check "php version 8.4.15 installed" ls -l /usr/local/php | grep 8.4.15
1110

1211
check "composer-version" composer --version
1312

test/php/scenarios.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"image": "ubuntu:noble",
44
"features": {
55
"php": {
6-
"version": "8.4.2",
7-
"additionalVersions": "8.3.14,8.2.27"
6+
"version": "8.5.0",
7+
"additionalVersions": "8.4.15",
8+
"installComposer": "true"
89
}
910
}
1011
},

0 commit comments

Comments
 (0)