@@ -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+
173198init_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} "
0 commit comments