Skip to content

Instantly share code, notes, and snippets.

@kumaxim
Created August 5, 2022 17:37
Show Gist options
  • Select an option

  • Save kumaxim/2aa3aba59a8692fa4eb2a14e49d38f1e to your computer and use it in GitHub Desktop.

Select an option

Save kumaxim/2aa3aba59a8692fa4eb2a14e49d38f1e to your computer and use it in GitHub Desktop.
Build PECL package on specific PHP version

One summer beautiful day I updated PHP from 7.4 to 8.0 and PHPStorm from 2019.3 to 2021.3 on my work station.

I used xDebug v2.9.8 from PECL on PHP 7.4 and xDebug v3.1.2 from Ubuntu repository ppa:ondrej/php on PHP 8.0

I wanted to preserve different version xDebug on different version PHP. Do not tell me Why :-)

This script build xDebug from PECL for PHP 7.4. Example usage:

./pecl-php-package-installer.sh 7.4 xdebug 2.9.8

You may use this code for building necessary version of xDebug or other PECL package on target PHP version.

However, if you will try to build the different version of the same package on different target PHP, the previous build of package was purged.

I not found the reason. Tell me if you know.

I build xDebug v2.9.8 for PHP 7.4 using this script and install xDebug v3.1.2 from apt.

Final result:

# ./pecl-php-package-installer.sh 7.4 xdebug 2.9.8
# php7.4 -v
PHP 7.4.30 (cli) (built: Aug  1 2022 15:06:20) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies
    with Xdebug v2.9.8, Copyright (c) 2002-2020, by Derick Rethans
# apt install php8.0-xdebug
# php8.0 -v
PHP 8.0.21 (cli) (built: Aug  1 2022 07:40:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.21, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.21, Copyright (c), by Zend Technologies
    with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans

P.S.: I got all what I wanted and back to the job.

#!/bin/bash
PHP_VERSION=$1
PECL_PACKAGE=$2
if [ -n "${3}" ]; then
PECL_PACKAGE="${PECL_PACKAGE}-${3}"
fi;
echo "Install PECL ${PECL_PACKAGE} ON PHP${PHP_VERSION}..."
echo "Run: update-alternatives --set php /usr/bin/php${PHP_VERSION}"
update-alternatives --set php /usr/bin/php${PHP_VERSION}
echo "Run: pecl config-set php_ini /etc/php/${PHP_VERSION}/cli/php.ini"
pecl config-set php_ini /etc/php/${PHP_VERSION}/cli/php.ini
echo "Run: pecl config-set ext_dir $(php${PHP_VERSION} -i | grep 'extension_dir' | awk '{print $3}')"
pecl config-set ext_dir $(php${PHP_VERSION} -i | grep 'extension_dir' | awk '{print $3}')
echo "Run: pecl config-set bin_dir /usr/bin"
pecl config-set bin_dir /usr/bin
echo "Run: pecl config-set php_bin /usr/bin/php${PHP_VERSION}"
pecl config-set php_bin /usr/bin/php${PHP_VERSION}
echo "Run: pecl config-set php_suffix ${PHP_VERSION}"
pecl config-set php_suffix ${PHP_VERSION}
echo "Run: pecl install -f ${PECL_PACKAGE}"
pecl install -f ${PECL_PACKAGE} > "pecl-${PECL_PACKAGE}-php${PHP_VERSION}.txt"
echo "PECL ${PECL_PACKAGE} ON PHP${PHP_VERSION} installed successfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment