给php安装xdebug扩展
安装扩展(前提是你的php也是用brew安装的)
brew install php55-xdebug --build-from-source
进入下面的目录打开xdebug配置文件:
cd /usr/local/etc/php/5.5/conf.d
vim ext-xdebug.ini
编辑如下:
[xdebug]
zend_extension="/usr/local/opt/php55-xdebug/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9010
xdebug.remote_log=/tmp/xdebug.log
xdebug.profiler_enable=0
xdebug.profiler_output_name=xdebug.cachegrind-out.%s.%p
xdebug.idekey="PHPSTORM"
配置完成后要重启php-fpm:
sudo php55-fpm restart
在index.php中加入phpinfo();die;并执行
若能在php的配置页面中看到xdebug的模块说明配置成功

chrome或firefox浏览器安装扩展

安装xdebug-helper扩展并开启,直到在浏览器工具栏可以看到激活状态的图标

phpstorm设置
进入phpstorm的偏好设置:
(1)Languages & Frameworks > PHP > Servers

(2)Languages & Frameworks > PHP > Debug > DBGp Proxy

(3) Languages & Frameworks > PHP > Debug

xdebug使用
-
在
chrome上启用xdebug-helper扩展,输入网址或请求的接口地址 -
在
phpstorm上开启xdeubg监听
-
刷新
chrome,在phpstorm中弹出xdebug窗口 -
单步调试

-
跳入,进入调用的方法体

-
跳出,离开方法体,返回原来执行的代码

报错
如果报下面的错误,说明端口号错误,确保设置的端口号与之前在ext-xdebug.ini中配置的是一致的。如果一致的还出现这种错误,那么换一个端口号试试

补充:Xdebug 3 之后,这篇的配置全要重写
原文基于 Xdebug 2.x + PHP 5.5,而 Xdebug 3(2020 年发布)重命名了一批配置项,直接套用原文的 ini 会导致断点打不上,且不报错。
1. 配置项改名对照
| 原文(Xdebug 2) | 今天(Xdebug 3) |
|---|---|
xdebug.remote_enable=on |
xdebug.mode=debug |
xdebug.remote_host / remote_port |
xdebug.client_host / client_port |
xdebug.remote_log |
xdebug.log |
xdebug.remote_handler |
已移除(只有 dbgp 一种) |
xdebug.profiler_enable |
xdebug.mode=profile |
xdebug.profiler_output_name |
xdebug.output_dir + xdebug.profiler_output_name |
最关键的一条:Xdebug 3 默认 xdebug.mode=develop,debug 是关着的。所以「按原文配完却死活不触发断点」,九成是漏了 xdebug.mode=debug。
2. 端口默认值也变了
Xdebug 2 默认 9000,Xdebug 3 默认 9003。而 9000 恰好是 PHP-FPM 监听的端口,这也是原文说「报错就换个端口」的历史原因之一。今天的 ini:
[xdebug]
zend_extension=xdebug
xdebug.mode=debug,develop
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=trigger
xdebug.idekey=PHPSTORM
xdebug.log=/tmp/xdebug.log
3. 不用再装浏览器插件了
原文装的 Xdebug Helper 已在 Chrome 应用商店下架。今天的主流做法:
- PhpStorm 自带的调试启动:点
Start Listening,然后直接用 IDE 里配置好的 Run Configuration 发起请求。 - 浏览器扩展替换品:
Xdebug helper的多个 fork 仍在(如 JetBrains 官方推荐的Xdebug Helper新版),但更稳妥的是命令行注入:
# 用 curl 触发调试,不依赖任何插件
curl -b "XDEBUG_SESSION=PHPSTORM" http://localhost/test.php
或用 xdebug.start_with_request=yes 让所有请求都带上调试(仅限本地,线上绝不能开)。
4. 安装方式
pecl install xdebug
brew install php55-xdebug 这条路早已不存在(php55 已从 Homebrew 移除)。
5. 端口冲突的现代排查
原文截图里那个「Waiting for incoming connection with ide key」弹窗,今天依然常见。最有效的一步是先看日志:
tail -f /tmp/xdebug.log
如果日志里根本没有连接记录,说明是 ini 没生效或 mode 没开 debug;如果有记录但 IDE 没反应,才是端口/防火墙问题。先看日志再盲改端口,能省很多时间。
本文整理于 2016 年,2026 年 11 月补充。