在 CentOS 上用 PhpStorm 调试 PHP,一般是通过 Xdebug 来实现。下面给你一套常见、可用的完整流程(以 PHP 7.x / 8.x + Xdebug 3 为例)。
php -v
如果你是 PHP 通过 yum/remi 安装:
sudo yum install php-xdebug
如果是编译安装 PHP,用 pecl:
pecl install xdebug
安装完成后确认:
php -m | grep xdebug
找到 php.ini(通常在 /etc/php.ini 或 /etc/php.d/ 下)
[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
⚠️ 如果你用的是 Xdebug 2,配置是:
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
重启 PHP:
systemctl restart php-fpm
# 或
systemctl restart httpd
File → Settings → PHPSettings → PHP → Debug9003(Xdebug3)Settings → PHP → Serverscentoslocalhost 或你的域名80XdebugDebugexport XDEBUG_MODE=debug
export XDEBUG_CONFIG="idekey=PHPSTORM"
php your_script.php
firewall-cmd --add-port=9003/tcp --permanent
firewall-cmd --reload
php -i | grep xdebug
如果你愿意,可以告诉我:
我可以给你 更精确的配置。