温馨提示×

怎么在CentOS调试PHPStorm

小樊
45
2026-08-03 19:19:40
栏目: 编程语言

下面分 “在 CentOS 上调试 PHP(用 PHPStorm)”“在 CentOS 上调试 PHPStorm 本身” 两种情况说明。
90% 的情况你是第一种,所以我重点讲 PHP 远程/本地调试(Xdebug)


一、在 CentOS 上调试 PHP(PHPStorm + Xdebug)

1️⃣ 安装 PHP 和 Xdebug

查看 PHP 版本

php -v

安装 Xdebug(以 PHP 7.4 为例)

yum install php-pear php-devel gcc make
pecl install xdebug

如果是 PHP 8.x,同样适用


2️⃣ 配置 Xdebug(php.ini)

找到 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

3️⃣ 配置 PHPStorm

① 设置 PHP 解释器

Settings → PHP → CLI Interpreter
  • 选择 CentOS 上的 PHP
  • 能看到 Xdebug 即成功

② 设置 Debug

Settings → PHP → Debug
  • Debug port:9003
  • 勾选 Can accept external connections

4️⃣ 设置调试方式

✅ 方式一:浏览器调试(最常用)

  1. 安装浏览器插件
    • Chrome:Xdebug Helper
  2. PHPStorm 点击 电话图标(Listen for Debug Connections)
  3. 访问页面并点击 Debug

✅ 方式二:PHPStorm 一键调试(推荐)

  1. 在代码行打 断点
  2. 右上角选择 PHP Script
  3. 点击 ▶ Debug

5️⃣ 常见问题排查

问题 解决
断点不生效 确认 Xdebug 已加载
连接超时 client_host / port 错误
9000 端口冲突 改用 9003
只执行不断点 start_with_request=yes

二、如果你是想「调试 PHPStorm 本身」

PHPStorm 是 Java 程序,在 CentOS 上调试方式不同:

1️⃣ 查看日志

~/.cache/JetBrains/PhpStorm*/log/

2️⃣ 开启 IDE 调试日志

Help → Diagnostic Tools → Debug Log Settings

3️⃣ 启动参数调试

编辑:

phpstorm.vmoptions

添加:

-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

三、我可以继续帮你

你可以直接告诉我:

  1. CentOS 7 还是 8 / Stream?
  2. PHP 版本?
  3. 本地调试还是远程服务器?
  4. Apache / Nginx / PHP-FPM?

我可以给你 精确到命令级别 的配置方案。

0