PHP调试利器XDebug Mac下在phpstorm中的安装与使用

Share on:

之前一直用比较原始的调试方法echo、print_r()、var_dump()、printf(),可能小项目比较小吧

最近有时间,就研究了Mac系统下集成phpstorm的xdebug安装配置使用,下面记录一下~

安装篇

1.xdebug的安装

下载地址https://xdebug.org/

我是直接用神器brew安装(版本号自行替换)

brew install homebrew/php/php56-xdebug

安装完毕后brew info homebrew/php/php56-xdebug 包含了很多信息 包括xdebug的配置文件路径,如何判断安装成功等等

2.配置xdebug

在/usr/local/etc/php/5.6/conf.d/ext-xdebug.ini

[xdebug]
zend_extension=”/usr/local/opt/php56-xdebug/xdebug.so”
xdebug.remote_enable=1
xdebug.remote_host=”127.0.0.1″
xdebug.remote_port=9001
xdebug.profiler_enable=1
xdebug.profiler_output_dir=”/Users/www/debug”
xdebug.idekey=”PHPSTORM”

3.在phpstorm中配置xdebug

上面都配置好后要在主菜单中,选择Run | Web Server Debug Validation.下图是验证成功的效果,但是没有那么顺利,报错Remote host is configured as “localhost” despite server host is probably not local,在stackoverflow有人说把xdebug.remote_host改成自己项目的域名就可以了,还真是不知道是为何。。。

4.phpstorm配置一个PHP Web Application

5.打开Chrome下载安装xdebug-helper,地址https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc

点开选项记得把IDE key配置得跟之前设置的一样

到这里安装配置就结束了~~~

使用篇

1.phpstorm 打开监听 Run | Start Listening For PHP Debug Connections

2.打个断点

3.访问项目域名,就可以在phpstorm中看到变量信息,点击红框,可以查看每次执行的代码行,也会看到因为执行代码行所赋值的变量。

还有一个就是php报错的时候回显示堆栈信息

参考

https://www.jetbrains.com/help/phpstorm/2016.2/configuring-xdebug.html

http://stackoverflow.com/questions/36001918/phpstorm-xdebug-remote-host-is-configured-as-localhost-despite-server-host

闽ICP备12003472号-7