在 CentOS 上使用 PhpStorm 调试 PHP,通常是通过 Xdebug 来实现。下面给你一套从零开始、可用的完整流程(适合本地或远程服务器)。
yum install php php-cli php-devel -y
yum install php-pear gcc
pecl install xdebug
安装完成后会看到类似:
/usr/lib64/php/modules/xdebug.so
php --ini
编辑 php.ini(或 /etc/php.d/xdebug.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 ; 你的 PhpStorm 所在电脑 IP
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
⚠️ 如果是 Docker / 虚拟机,client_host 很重要
systemctl restart php-fpm
# 或
systemctl restart httpd
php -m | grep xdebug
File → Settings → PHPSettings → PHP → Debug9003Can accept external connectionsSettings → PHP → Serverscentos192.168.1.10080XdebugURL 也可手动加参数:
?XDEBUG_SESSION=PHPSTORM
export XDEBUG_SESSION=PHPSTORM
php test.php
netstat -tunlp | grep 9003
client_host=host.docker.internal如果你愿意,可以告诉我:
我可以给你量身定制的配置示例。