PhpStorm 远程调试 CentOS 上的 PHP 实战指南
一 环境准备与版本选择
二 在 CentOS 上安装并配置 Xdebug
sudo yum install php-xdebug(不同系统/版本仓库可能提供不同版本)。sudo pecl install xdebug,记录输出的 xdebug.so 路径,后续在配置中引用。[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=<你的本地开发机IP>
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.idekey=PHPSTORM
xdebug.start_with_request=yes 会在每次请求时主动连接调试器,便于无侵入触发;也可设为 trigger 配合触发参数使用。[xdebug]
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=<你的本地开发机IP>
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1
sudo systemctl restart php-fpmsudo systemctl restart httpdphp -v,应看到包含 with Xdebug 的字样。php -m | grep xdebug,应能看到 xdebug。php --ini 确认加载的配置文件与路径是否正确。三 在 PhpStorm 中配置远程调试
四 触发调试与常见问题排查
?XDEBUG_SESSION_START=PHPSTORM(或使用 Xdebug Helper 等浏览器扩展一键开启)。xdebug.start_with_request=yes,直接访问即可触发。ss -lntp | grep 9003 检查占用,必要时更换 xdebug.client_port(同时在 PhpStorm 的 Debug 配置中同步修改)。五 Xdebug 2 与 3 关键差异对照
| 维度 | Xdebug 2.x | Xdebug 3.x |
|---|---|---|
| 启用调试 | xdebug.remote_enable=1 |
xdebug.mode=debug |
| 客户端地址 | xdebug.remote_host=<IP> |
xdebug.client_host=<IP> |
| 端口 | xdebug.remote_port=9000 |
xdebug.client_port=9003 |
| 自动启动 | xdebug.remote_autostart=1 |
`xdebug.start_with_request=yes |
| IDE Key | xdebug.idekey=PHPSTORM |
xdebug.idekey=PHPSTORM |