Installing XDebug for PHP with XAMPP on Mac

2019-04-28 09:50发布

问题:

I have a Mac with a fresh OSX Mojave install. I downloaded XAMPP (7.3) and installed. The local Apache web server works and the PHPInfo() I get from the dashboard shows all the correct information for the php.ini file being the /Applications/XAMPP/xamppfiles/etc/php.ini.

I have taken a copy of the PHPInfo and put it in the wizard at:

https://xdebug.org/wizard.php

The instructions look simple. I did have to use homebrew to install autoconf first.

But then I was able to download and unpack the xdebug-2.6.1.tgz in the /Applications/XAMPP/xamppfiles/ folder.

I changed my $PATH variable to have /Applications/XAMPP/xamppfiles/bin be the first path searched, so that the correct phpize would run.

I changed to the /Applications/XAMPP/xamppfiles/xdebug-2.6.1 folder and ran phpize, then I ran ./configure. Everything seemed to run well with no perceived errors.

But then I got errors when I ran the "make" command. Here is the output I got:

> Terrys-MacBook-Pro:xdebug-2.6.1 terry$ make /bin/sh
> /Applications/XAMPP/xamppfiles/xdebug-2.6.1/libtool --mode=compile cc 
> -I. -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1 -DPHP_ATOM_INC -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1/include -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1/main -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1 -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /Applications/XAMPP/xamppfiles/xdebug-2.6.1/xdebug_compat.c -o
> xdebug_compat.lo   cc -I.
> -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1 -DPHP_ATOM_INC -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1/include -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1/main -I/Applications/XAMPP/xamppfiles/xdebug-2.6.1 -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Applications/XAMPP/xamppfiles/xdebug-2.6.1/xdebug_compat.c 
> -fno-common -DPIC -o .libs/xdebug_compat.o /Applications/XAMPP/xamppfiles/xdebug-2.6.1/xdebug_compat.c:56:71:
**> error: too few arguments to function call, expected 6, have 5**
>         return zend_get_zval_ptr(op_type, node, zdata, &should_free, BP_VAR_R);
>                ~~~~~~~~~~~~~~~~~                                             ^
> /Applications/XAMPP/xamppfiles/include/php/Zend/zend_execute.h:330:1:
> note: 'zend_get_zval_ptr' declared here ZEND_API zval
> *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type); ^ /Applications/XAMPP/xamppfiles/include/php/main/php_config.h:9:19:
> note: expanded from macro 'ZEND_API'
> # define ZEND_API __attribute__ ((visibility("default")))
>                   ^ /Applications/XAMPP/xamppfiles/xdebug-2.6.1/xdebug_compat.c:194:88:
> error: too few arguments to function call, expected 9, have 8
>         php_setcookie(name_s, value_s, expires, path_s, domain_s, secure, url_encode, httponly);
>         ~~~~~~~~~~~~~                                                                         ^ /Applications/XAMPP/xamppfiles/include/php/ext/standard/head.h:40:1:
> note: 'php_setcookie' declared here PHPAPI int
> php_setcookie(zend_string *name, zend_string *value, time_t expires,
> zend_string *path, zend_string *domain, int secure, int httponly,
> zend_string *samesite, int url_encode); ^
> /Applications/XAMPP/xamppfiles/include/php/main/php.h:72:18: note:
> expanded from macro 'PHPAPI'
> #               define PHPAPI __attribute__ ((visibility("default")))
>                               ^ 2 errors generated. make: *** [xdebug_compat.lo] Error 1

So the first error I see in the "make" command is "> error: too few arguments to function call, expected 6, have 5".

I have no idea where to go from here. The endless documents I've read either seem to be for PC or for PHP 5.

回答1:

There is a bug for this. The link is thus: https://bugs.xdebug.org/view.php?id=1593

Which describes that you need to use Xdebug 2.7.0beta1 for now.



回答2:

Hannibal is correct, but his answer is a bit terse so I want to expand on it a bit.

This is a XDebug bug for PHP 7.3.x so you'll need to install XDebug 2.7.0beta1:

$ pecl install xdebug-2.7.0beta1

Since I installed the latest PHP version using Homebrew, the XDebug installation actually threw two mkdir() errors. This was because there was already a pecl symlink in Homebrew's PHP directory.

First I wanted to verify that, so I ran $ ls -al /usr/local/Cellar/php/<YOUR_PHP_VERSION_NUMBER>

If you have any doubt about your PHP version, it should be in the pecl installation log and listed right alongside the mkdir() errors.

Once I confirmed that there was already a symlink there, I simply removed it:

$ rm /usr/local/Cellar/php/<YOUR_PHP_VERSION_NUMBER>/pecl

After I did that, I ran the install again and it worked smoothly.

Of course, $ php --ini showed errors, so I had to configure PHP properly. Gabor Javorsky actually wrote a great article which includes how to ensure XDebug gets loaded correctly and it worked perfectly for me. See Step 2 in his article here: https://javorszky.co.uk/2018/05/03/getting-xdebug-working-on-php-7-2-and-homebrew/.

Don't forget to reload PHP after tweaking your config, which for me was:

$ brew services stop php@7.2 && brew services start php@7.2

After that, $ php --ini should show no errors!



标签: php xampp xdebug