在phpstorm中使用xdebug

本文阅读大概需要 2 分钟

开启xdebug

php.ini中配置xdebug如下:

[xdebug]
xdebug.remote_enable = On
xdebug.remote_handler = dbgp
xdebug.remote_host= localhost
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.profiler_enable = 1

重启服务之后在phpinfo中查看是否已经开启xdebug.

配置phpstorm

  1. 配置xdebug端口号

    在 File > Settings > Langauges&Frameworks 中找到 PHP 选择Debug选项卡,找到xdebug配置项,确认端口号是上面设置的9000

  2. 配置DBGp Proxy

    点击DBGp Proxy选项卡,在里面设置:

    IDE Key: PHPSTORM
    Host: localhost
    Port: 9000

  3. 添加 servers

    找到 Servers选项卡,点击添加按钮添加一个配置信息。例如想调试部署好的虚拟地址:www.app.local,那么你需要在Host中填上该地址。
    注意Port需要和你实际配置的端口要一直。另外保证DebuggerXdebug

这里主要记录下如何配合浏览器插件Xdebug helper来进行调试

安装浏览器插件Xdebug helper

安装成功之后,在选线卡将你配置的domain进行添加。

在postman中使用xdebug

  1. Configure your xdebug (by editing php.ini) to attempt to debug every php script (xdebug.remote_autostart = 1)

  2. Add xdebug session start parameter to the actual URL (XDEBUG_SESSION_START= – http://xdebug.org/docs/remote ), for example: ?XDEBUG_SESSION_START=PHPSTORM

  3. Pass xdebug cookie as one of the headers (the one which is set by bookmarklet or browser extension, for example)

    参考文章: