Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable Xdebug for MacOS Big Sur? "php -m" show its ok, but "phpinfo();" don't

I just updated my MacOS to Big Sur and my localhost configuration was a mess. After reinstalling PHP and Xdebug, it seems my Xdebug is not working properly. I can see it is installed through php -m, but it is not listed in phpinfo();. Also, If I open a VSCode, start "Listen for XDebug", add a breakpoint to a file and run php -e FILENAME.php, the breakpoint works, but if I do the same using a browser, is doesn't.

Already tried the official tutorial that used homebrew and several other tutorials, since from installing it manually until doing all stuff automated. I'm out of clues here, any help or ideas are welcome. Thanks in advance.

Below follows my config:

  • PHP: 7.4.10
  • Xdebug config in php.ini
[xdebug]
zend_extension="/usr/local/Cellar/php/7.4.10/lib/php/20190902/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
  • VSCode launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "xdebugSettings": {
                "max_data": -1
            }
        }
    ]
}
  • "php -m" output
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
Phar
phpdbg_webhelper
posix
pspell
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache
  • phpinfo() output (compacted since stackoverflow adds limit here)
PHP logo
PHP Version 7.4.10
...
Server API  Apache 2.0 Handler
Virtual Directory Support   disabled
Configuration File (php.ini) Path   /usr/local/etc/php/7.4
Loaded Configuration File   /usr/local/etc/php/7.4/php.ini
Scan this dir for additional .ini files /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed    /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/ext-xdebug.ini
PHP API 20190902
PHP Extension   20190902
Zend Extension  320190902
Zend Extension Build    API320190902,NTS
PHP Extension Build API20190902,NTS
...
This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.4.0, Copyright (c) Zend Technologies
...

Edit: Double checked both "php -i" and "phpinfo();", the mention the same php.ini file: /usr/local/etc/php/7.4/php.ini

like image 583
Felyppe Rodrigues Avatar asked Sep 16 '20 21:09

Felyppe Rodrigues


People also ask

How does PHP xDebug work?

When Xdebug is running, it will call back to your IDE (like PhpStorm or VS Code) from the server where it's running. Your IDE will sit and listen for that connection on a specific port (typically port 9000 or 9003).


2 Answers

When I had this issue after upgrading to big sur, it was caused by :

Failed loading /usr/local/lib/php/pecl/20200930/xdebug.so: dlopen(/usr/local/lib/php/pecl/20200930/xdebug.so, 9): no suitable image found. Did find: /usr/local/lib/php/pecl/20200930/xdebug.so: code signature in (/usr/local/lib/php/pecl/20200930/xdebug.so) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

After trying to create/find a signed xdebug.so or to turn off signing verification on my mac for far too long I eventually solved the issue by installing a new httpd with brew.

like image 58
james.c.funk Avatar answered Sep 29 '22 11:09

james.c.funk


Here is what I did to make xdebug work under Big Sur

There are two signed files located in /usr/lib/php/extensions/no-debug-non-zts-20180731 - xdebug.so and opcache.so but they will not work with PHP greater than 7.3

If you can downgrade to 7.3 then

  1. Use brew to install php 7.3: brew install [email protected]
  2. Update httpd.conf according to brew instructions
  3. Switch to 7.3 if you under different version: brew unlink php && brew link --force --overwrite [email protected]
  4. Add this section at the end of 7.3 php.ini:
    [xdebug]
    zend_extension = "/usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so"
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
  1. Restart Apache server

  2. Check is Xdebug is enabled: php -i | grep "xdebug support"

like image 42
Pavel Popov Avatar answered Sep 29 '22 09:09

Pavel Popov