I want to install multiple versions Xdebug based in each version in brew

278 Views Asked by At

I have multiple versions of PHP using brew. When I want to switch between for example from PHP 7.4 to PHP 8.1 I use this command

brew unlink [email protected] && brew link [email protected]

When I download Xdebug for PHP 8.1 I use

pecl install xdebug

It would install Xdebug's latest version until now. So if I write

pecl list

I get

Package Version State
imagick 3.7.0   stable
xdebug  3.2.2   stable

When I open /usr/local/etc/php/8.1/php.ini I get

zend_extension="xdebug.so"

That's fine until now.

Now the problem is when I want to install a lower version for my PHP 7.4 (because the newer version of Xdebug is not compatible with PHP 7.4). So according to this page I should download at most xdebug-3.1 for PHP 7.

So I will switch to PHP 7 using

brew unlink [email protected] && brew link [email protected]

then I download a compatible Xdebug version with PHP 7.4 using this command

pecl install xdebug-3.1.6

It will be downloaded fine, but I get this issue whenever I use PHP, e.g php -v

Failed loading /usr/local/opt/[email protected]/pecl/20210902/xdebug.so:  dlopen(/usr/local/opt/[email protected]/pecl/20210902/xdebug.so, 0x0009): symbol not found in flat namespace (_instanceof_function_slow)

I guess because it didn't know the path for Xdebug.

If I open /usr/local/etc/php/7.4/php.ini I get

zend_extension="xdebug.so"

I tried to change the path in php.ini in PHP 7 to /usr/local/opt/[email protected]/pecl/20210902/xdebug.so because there is an Xdebug file in this path, but the problem remains.

How can I fix this problem?

1

There are 1 best solutions below

0
zobo On

You are loading xdebug.so compiled for the wrong PHP version. For PHP 7.4 you should see if you have .../pecl/20190902/xdebug.so file. Then check your active php.ini to see where the extensions are loaded from, see extension_dir php.ini directive.

Details:

The Failed loading error tells me two things.

First, the loaded .so file depends on the exported function _instanceof_function_slow. This is something that is present in the PHP-8 branch but not in the PHP 7.4 brnach.

The second is the API Version in the path /usr/local/opt/[email protected]/pecl/20210902/xdebug.so. The 20210902 API version corresponds to PHP 8.1, where as PHP 7.4 uses 20190902. I was not able to find a list on the official site (aside from looking at the source), but here is one link that lists the versions for reference.

PHP Version API Version
7.4 20190902
8.1 20210902

My guess is that brew link/unlink keeps the same pecl directory (/usr/local/opt/[email protected]/pecl == /usr/local/opt/[email protected]/pecl) and/or that the php.ini needs adjusting.

To debug things I'd suggest the following:

  • pecl list when PHP 7.4 is active
  • list and inspect the contents of /usr/local/opt/[email protected]/pecl and /usr/local/opt/[email protected]/pecl if there are more API version folders (looking for 20190902 and 20210902)
  • inspect active extension folder by php -i | grep extension_dir
  • check if there are any references to pecl folders php -i | grep -i pecl
  • see if there are any magic symlinks for extension_dir and pecl
  • try to load zend_extension="/usr/local/opt/[email protected]/pecl/20190902/xdebug.so"