15

So macOS High Sierra 10.13 now comes with PHP 7.1. While configuring Apache I also created a new /etc/php.ini from the /etc/php.ini.default file, made sure to check that is was being loaded by PHP after restarting Apache, however the version of Xdebug extension that ships with macOS 10.13 doesn't seem to load or show up when you run phpinfo();

My php.ini is definitely being loaded:

$ php -i | grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

Here's what my /etc/php.ini looks like where I configure Xdebug:

[xdebug]    
zend_extension = "/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000

[Update, fixed that typo here...]

However, Xdebug doesn't load and checking php -i give no results:

$php -i | grep xdebug
PHP Warning:  Method xdebug_start_function_monitor() cannot be a NULL 
    function in Unknown on line 0
    PHP Warning:  xdebug: Unable to register functions, unable to load in Unknown on line 0
    Segmentation fault: 11

And yes, the path to the file is correct:

$ ls /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so*

This used to work on PHP 5 so I hope someone can help me and anyone else in future struggling with this issue.

When I check my apache log I get the following error:

Failed loading /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so:  dlopen(/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so, 9): Symbol not found: _xdebug_monitored_function_dtor
  Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
  Expected in: flat namespace
 in /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so

I'm not making progress in terms of find out how I can resolve this error:

Symbol not found: _xdebug_monitored_function_dtor
Gerard de Jong
  • 608
  • 1
  • 5
  • 11
  • Please note that Apache *may* be using different php.ini (one php.ini is used for CLI/terminal and one by Apache/web sever). So it's better to check `phpinfo()` output captured in actual browser to see what php.ini is used and if xdebug is loaded. Sure, if they both use the same ini file then such checks can be performed in terminal. And yes --`zend_extension` with full path (safer) – LazyOne Oct 06 '17 at 09:44
  • Thanks, I checked both CLI and browser and they are both loading the same php.ini file. – Gerard de Jong Oct 07 '17 at 17:32
  • FWIW, it looks like Apple fixed it in an update. It works in macOS 10.13.6 :) – Fuzzy76 Aug 03 '18 at 12:30

6 Answers6

25

Ok so I finally got it running myself it works perfectly! I'm assuming that the xdebug binary that comes with macOS High Sierra (found under: /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so) is not compatible with PHP7's new Zend engine.

So I downloaded the latest source from the xdebug website and did the following:

  1. Installed autoconf with brew;
  2. Run phpize to configure the build for the new Zend engine;
  3. Run ./configure
  4. Run make

Now the new binary is under modules/xdebug.so

However macOS System Integrity Protection (SIP) will prevent you from overwriting the xdebug.so under /usr/lib/php/extensions/. I didn't want to disable this so I created a new directory path under /usr/local/lib/php/extensions/ and copied the new binary to this location. I'm not sure if this directory is the best place to put it or if this is bad practice but it worked for me.

Finally I reconfigured my php.ini to use the new binary and everything worked perfectly!

Gerard de Jong
  • 608
  • 1
  • 5
  • 11
  • I cloned the git repository, and tried to reproduce your steps 1-4. But I do get an error messages: fatal error: 'php.h' file not found – Mondy Oct 09 '17 at 08:51
  • I had this at first myself. I can't recall exactly what fixed this for me, I think it was either installing autoconf or upgrading to Xcode 9.0. I think it must have been autoconf as this allowed my compiler to see the php.h header which I suppose is included in the latest PHP installation. – Gerard de Jong Oct 10 '17 at 11:24
  • 1
    I got this `Failed loading /usr/local/php/extensions/xdebug.so: dlopen(/usr/local/php/extensions/xdebug.so, 0x0009): code signature in (/usr/local/php/extensions/xdebug.so) not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.` – abbood Oct 20 '18 at 08:30
  • i got the same error as @abbood , can someone please help? – Ali123 Nov 06 '18 at 17:31
  • I added this in php.ini and still getting the error zend_extension=/usr/local/php/extensions/xdebug.so – Ali123 Nov 06 '18 at 17:32
  • 4
    @Ali123 Just wrote zend_extension=xdebug.so, there's no need an absolute path – Moe Far Jun 18 '19 at 04:04
  • Thanks @MoeFar , I used the [wizard](https://xdebug.org/wizard) and prepared an absolute path with a subfolder `no-debug-non-zts-20180731`, – Timo Oct 14 '20 at 17:37
9

In order to install it you have to have xcode command line tools.

So you need to run:

xcode-select --install

Then you need to install autoconf:

brew install autoconf

Then you have to download the code from here. After that you have to run in the folder of the source code:

  1. phpize
  2. ./configure
  3. make
  4. sudo cp modules/xdebug.so /usr/local/php/extensions (if the directory doesn't exist go and create it)

And finally inside php.ini add

zend_extension=/usr/local/php/extensions/xdebug.so

After that you can enable xdebug inside php.ini and restart apache

sudo apachectl restart
Jeremy Moritz
  • 13,864
  • 7
  • 39
  • 43
4

you made a typo in "zend_extention". this should be zend_extension. and i think the full path is unnecessary zend_extension=xdebug.so should be enough

user24525
  • 423
  • 3
  • 8
2

If you have brew installed with multiple PHP versions i.e. 7.1, 7.2 and 7.3 on Mac OS X mojave, you can to do the following:

  1. Install autoconf with brew brew install autoconf.

  2. Change to the PHP version that you want Xdebug on, run brew unlink php@7.1 && brew link --force --overwrite php. This will switch from PHP 7.1 to PHP 7.3.

  3. Download the latest Xdebug source from xdebug website.

  4. Extract the Xdebug tar and navigate to extracted directory, where you'd see all the files.

  5. Run phpize to configure the build for the new Zend engine.

  6. Run ./configure.

  7. Run make.

  8. Xdebug extension xdebug.so gets compiled in modules directory.

  9. Create a new directory path under /usr/local/lib/php/7.3.1/extensions/ and copy xdebug.so to this location. Here, 7.3.1 is the current version that I switched earlier, change this to match your PHP version.

  10. Open php.ini in an editor and enter zend_extension="/usr/local/lib/php/7.3.1/extensions/xdebug.so" then save the change.

  11. Run php -v and it will show Xdebug has been configured correctly.

If you want to configure Xdebug on another PHP version then just repeat from step 2 all the way to 11. As mentioned in earlier post, this way you don't need to disable/enable System Integrity Protection on Mac OS X.

Asrar
  • 427
  • 4
  • 11
0

For anyone arriving late at this party, the initial attempt in the question seems to work just fine in macOS 10.13.6

Fuzzy76
  • 891
  • 1
  • 6
  • 14
0

Hello for everyone that got error trying to install xDebug on Mac.

error: unknown type name 'uint64_t'

There are files in your local/bin/include that causes this error. By removing them you get rid of the error. Though, you might have to reinsatall brew.

https://github.com/cython/cython/issues/2009

jenel
  • 21
  • 2
  • Please specify which files we should be deleting. Even from your source given this is not clear. – harmonica141 Apr 26 '19 at 11:59
  • From https://github.com/cython/cython/issues/2009#issuecomment-481395357 all files in "/usr/local/include" . Note, I havn't that many other installations via Homebrew, but I had a node file that I left alone and erease everything else, and that worked. – jenel Apr 29 '19 at 07:45