3

I am searching the way to debug php scripts. In internet i found information that i can do that with MacGDBp + XDebug. When i'm trying install using PECL in Shell:

sudo pecl install xdebug

The next error have been occured:

downloading xdebug-2.4.0.tgz ...

Starting to download xdebug-2.4.0.tgz (264,832 bytes)
.....................done: 264,832 bytes

76 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory

grep: /usr/include/php/Zend/zend_modules.h: No such file or directory

grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory

Configuring for:
PHP Api Version:

Zend Module Api No:

Zend Extension Api No:

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

Help me find the way to solve that problem.

Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
Oleg Savelyev
  • 275
  • 4
  • 16

3 Answers3

9

XDebug is available by default. Just enable it by

1) sudo nano /etc/php.ini (or sudo cp /etc/php.ini.default /etc/php.ini first if the file doesn't yet exist)

2) Add these lines at the end (verify the path with ls ls /usr/lib/php/extensions/)

[Xdebug]
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"

3) Restart apache using sudo apachectl restart

4) Verify by php -m | grep xdebug

Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
  • I am trying to do the first step: Edit /etc/php.ini using VIW, but it creates new PHP.ini file. Is that normally? – Oleg Savelyev Apr 27 '16 at 11:02
  • `sudo cp /etc/php.ini.default /etc/php.ini` Then edit it with `sudo nano /etc/php.ini` – Harikrishnan Apr 27 '16 at 11:15
  • I am trying but - cp: /etc/php.ini.default: No such file or directory – Oleg Savelyev Apr 27 '16 at 12:12
  • Try `sudo cp /private/etc/php.ini.default /private/etc/php.ini` – Harikrishnan Apr 27 '16 at 12:18
  • cp: /private/etc/php.ini.default: No such file or directory... But I can found php.ini file in that catalogue. – Oleg Savelyev Apr 27 '16 at 12:29
  • I've found file PHP.ini and there is rows: zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so xdebug.file_link_format="txmt://open?url=file://%f&line=%1" xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.default_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=localhost xdebug.remote_port=9000 – Oleg Savelyev Apr 27 '16 at 12:33
  • Put a phpinfo and find your correct php.ini. Check section loaded config. – Harikrishnan Apr 27 '16 at 12:36
  • The string ls /usr/lib/php/extensions/ shows no-debug-non-zts-20121212 . Is that normal? – Oleg Savelyev Apr 27 '16 at 12:37
  • Now I am trying wrote the string: sudo peel install xdebug -> and the result now is: downloading xdebug-2.4.0.tgz ... Starting to download xdebug-2.4.0.tgz (264,832 bytes) .....done: 264,832 bytes 76 source files, building running: phpize Configuring for: PHP Api Version: 20121113 Zend Module Api No: 20121212 Zend Extension Api No: 220121212 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. _________________________________________________________How to find autoconf ? – Oleg Savelyev Apr 27 '16 at 12:41
  • INSTALL AUTOCONF: curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz tar xzf autoconf-latest.tar.gz cd autoconf-* ./configure --prefix=/usr/local make sudo make install Details here: http://stackoverflow.com/questions/9322742/php-autoconf-errors-on-mac-os-x-10-7-3-when-trying-to-install-pecl-extensions/12333230#12333230 – Oleg Savelyev Apr 27 '16 at 12:57
  • Put a phpinfo and find your correct php.ini. Check section loaded config. – Harikrishnan Apr 27 '16 at 13:02
2

Mike Chamberlain's excellent response almost got xdebug working with NetBeans using Mac OS Sierra 10.12. Only two changes required: In step 2, after zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" also add xdebug.remote_enable=1

This was necessary because the precompiled .so file has xdebug remote access disabled. NetBeans and other tools need it to be enabled.

Tibbs
  • 21
  • 3
0

For debugging using xdebug i used the following steps

For installing php72 I installed using brew with the following command:

brew install homebrew/php/php72-xdebug

I added the following command to the bottom of the php.ini file:

zend_extension=/usr/local/Cellar/php72-xdebug/2.6.0/xdebug.so

Note: if you need to search for a version of xdebug with brew use:

brew search xdebug
CodeGuyRoss
  • 786
  • 1
  • 10
  • 23
  • I am getting error - `Error: homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.` – Joozty Apr 30 '18 at 10:34