今天在mac下,想调试php代码,发现netbeans 挂不上断点,根本调试不了。一番搜索发现有个php的第三方模块叫xdebug ,虽然只找到一些windows 下的资料,但还是摸索着把调试环境搭建成功。

 

    配置过程:

 

安装xdebug

 

修改php.ini

重启apache

确认netbeans 的调试端口与xdebug 一致

    (1)下载xdebug

    我这里使用了brew, 如果对brew工具不熟悉的可以谷歌下。

   

    首先习惯性搜索下:

    终端里执行命令:brew search xdebug 发现的确有一个软件xdebug。

 

    然后  brew install xdebug ,一路顺风顺水 。安装完毕有提示安装的情况。

 

    没记住没关系:brew info xdebug

 

[hechangmin@hecm-mac ~]$brew info xdebug

xdebug 2.1.2

https://xdebug.org

/usr/local/cellar/xdebug/2.1.2 (348k)

 

to use this software:

  * add the following line to php.ini:

    zend_extension=”/usr/local/cellar/xdebug/2.1.2/xdebug.so”

  * restart your webserver.

  * write a php page that calls “phpinfo();”

  * load it in a browser and look for the info on the xdebug module.

  * if you see it, you have been successful!

 

https://github.com/mxcl/homebrew/commits/master/library/formula/xdebug.rb

    看有提示我们修改php.ini,这就是我们要做的第二步。

 

(2)修改php.ini 文件

   

    因为我安装的xmapp 所以找到默认的路径:sudo vi /applications/xampp/etc/php.ini

   

    增加:

        zend_extension=”/usr/local/cellar/xdebug/2.1.2/xdebug.so”

        xdebug.remote_enable=1 

        xdebug.remote_host=localhost 

        xdebug.remote_port=9000 

        xdebug.remote_handler=dbgp 

   

(3)重启apache

   

在终端下以管理员root 的身份登录:

sudo su

 

 

 

使用下面的命令启动xampp:

/applications/xampp/xamppfiles/xampp start

 

您应该能在屏幕上看到类似下面的提示信息:

 

starting xampp for macos x 1.7.3…

xampp: starting apache with ssl (and php5)…

xampp: starting mysql…

xampp: starting proftpd…

xampp for macos x started.

 

 (4)  确认nb 调试端口

 

     打开netbeans ,选择偏好设置,在调试器端口选择如第二步中的9000端口。并且勾选 ‘在第一行停止’(可选),这是为了防止为打断点就直接运行完了。

 

     到此全部完成。其中需要注意一点的是,在创建php项目的时候,会让你选择调试的hosts , 记得要调试的url 别写错了。

 

 

作者  -274°c