当前位置:编程学习 > php >>

MAC 下 netbeans xdebug 调试PHP代码

 

今天在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

http://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!

 

http://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

补充:Web开发 , php ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,