下面以 PhpStorm + Xdebug 在 CentOS 上调试 PHP 为例,给你一个完整、可落地的配置步骤(常用场景:本地代码 → CentOS 上跑 PHP)。
php -v
yum install php-pear php-devel
pecl install xdebug
如果是 PHP 8.x,同样用
pecl install xdebug
找到 php.ini:
php --ini
在末尾添加(或修改):
[xdebug]
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_host=192.168.1.100 ; 你电脑的 IP(PhpStorm 所在机器)
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
⚠️
client_host不是 CentOS IP,而是你 Windows / Mac 的 IP
重启 PHP:
systemctl restart php-fpm
# 或
systemctl restart httpd
验证:
php -m | grep xdebug
Settings → PHP → CLI Interpreter
→ + → From Docker / Remote / Local
(如果是远程 CentOS,用 SSH Interpreter)
Settings → PHP → Debug
→ Xdebug → Debug port: 9003
Settings → PHP → Debug → DBGp Proxy
IDE key: PHPSTORM
Host: CentOS IP
Port: 9003
PHPSTORMcurl "http://centos-ip/test.php?XDEBUG_TRIGGER=1"
或在 Header 加:
Cookie: XDEBUG_SESSION=PHPSTORM
Run → Edit Configurations
→ PHP Web Page
→ Server
→ 设置:
CentOS路径: /var/www/html
Local路径: D:/project
否则会显示:
“Cannot find file in project”
firewall-cmd --add-port=9003/tcp --permanent
firewall-cmd --reload
setsebool -P httpd_can_network_connect 1
CentOS php.ini
xdebug.mode=debug
xdebug.client_host=你的IP
xdebug.client_port=9003
PhpStorm
如果你愿意,可以告诉我:
我可以给你精确到命令的配置方案。