天天看点

在phpStorm中使用xdebug调试

<a href="#1-%e7%8e%af%e5%a2%83%e8%af%b4%e6%98%8e">环境说明</a>

<a href="#2-%e9%85%8d%e7%bd%aephpini">配置phpini</a>

<a href="#3-%e9%85%8d%e7%bd%aephpstorm">配置phpstorm</a>

<a href="#4-xdebug%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86%e8%af%b4%e6%98%8e">xdebug工作原理说明</a>

在mac下搭建的lnmp环境,可以参考:

<a href="http://blog.csdn.net/alex_my/article/details/53818143">mac搭建lnmp环境</a>

<a href="http://blog.csdn.net/alex_my/article/details/53818143">http://blog.csdn.net/alex_my/article/details/53818143</a>

nginx中的网站配置:

环境均使用brew安装,其中xdebug被安装到:

php的配置中也有指向

/usr/local/etc/php/5.6/php.ini

xdebug.remote_mode:

需要注意的是,这里不要再添加以下配置,会出现警告: 已经加载了xdebug.so

还有一个重要的是,如果你用的是nginx,并且是默认配置,一般9000端口都是被使用的。

按照网上其它教程做而xdebug无法断点的原因就是使用了以下配置:

重启php-fpm

打开 phpstorm–preferences–languages &amp; frameworks – php

点击debug, 填写以下内容

打开debug–dbgp proxy填写以下内容

打开网站工程,ide右上角,点击edit configurations..

点击弹出框左侧的+号。

选择php web application

此时左侧多了一列php web application – unnamed (改名为start)

在右侧 – configuration – server 右侧的 …

在弹出框servers左侧点击+号,填写以下内容

一些就绪后,在ide的右上侧,绿色三角形右侧,有一个臭虫按钮,打好断点,就可以点击使用了

ide中安装了一个遵循bgdp协议的xdebug插件, 称为xdebug-a

调试模式下,ide中的xdebug-a创建服务,监听端口: 9001(在phpstorm中设置的)

ide在当前url后面加上了xdebug_session_start参数

php服务器中的xdebug模块,称为xdebug-b, 接收到带有xdebug_session_start的请求后,会进入到调试模式

xdebug-b会以协议(bgdp)向xdebug-a的服务建立连接,提供调试服务。

php.ini中配置的xdebug.remote_host:xdebug.remote_port是xdebug-a的地址和端口

xdebug-a创建服务时,这个端口不能被其它进程占用了。

<a href="#">top</a>

继续阅读