下面分 “在 CentOS 上调试 PHP(用 PHPStorm)” 和 “在 CentOS 上调试 PHPStorm 本身” 两种情况说明。
90% 的情况你是第一种,所以我重点讲 PHP 远程/本地调试(Xdebug)。
php -v
yum install php-pear php-devel gcc make
pecl install xdebug
如果是 PHP 8.x,同样适用
找到 php.ini:
php --ini
添加或修改:
[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes
⚠️ Xdebug 3 默认端口是 9003(不是 9000)
重启 PHP:
systemctl restart php-fpm
# 或
systemctl restart httpd
验证:
php -i | grep xdebug
Settings → PHP → CLI Interpreter
Settings → PHP → Debug
9003| 问题 | 解决 |
|---|---|
| 断点不生效 | 确认 Xdebug 已加载 |
| 连接超时 | client_host / port 错误 |
| 9000 端口冲突 | 改用 9003 |
| 只执行不断点 | start_with_request=yes |
PHPStorm 是 Java 程序,在 CentOS 上调试方式不同:
~/.cache/JetBrains/PhpStorm*/log/
Help → Diagnostic Tools → Debug Log Settings
编辑:
phpstorm.vmoptions
添加:
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
你可以直接告诉我:
我可以给你 精确到命令级别 的配置方案。