在 CentOS 上使用 PhpStorm 调试 PHP,通常是通过 Xdebug 来实现。下面给你一套完整、可操作的步骤(以 PHP 7.x / 8.x + Xdebug 3 为例)。
yum install php php-cli php-devel
CentOS 推荐用 pecl:
yum install php-pear
pecl install xdebug
安装完成后会提示类似:
You should add "zend_extension=/usr/lib64/php/modules/xdebug.so" to php.ini
编辑 PHP 配置文件(路径可能不同):
php --ini
一般在:
/etc/php.ini
在末尾添加(Xdebug 3 示例):
[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes
如果你用 Docker / 虚拟机,
client_host要改成 宿主机 IP
重启 PHP:
systemctl restart php-fpm
# 或
systemctl restart httpd
验证:
php -m | grep xdebug
File → Settings → PHPSettings → PHP → DebugSettings → PHP → Serverscentoslocalhost 或服务器 IP80Xdebug安装:
PHPSTORM访问页面即可触发调试
path mappingsxdebug.mode=debugxdebug.client_host=192.168.x.x
xdebug.discover_client_host=0
firewall-cmd --add-port=9003/tcp --permanent
firewall-cmd --reload
pecl install xdebug
# php.ini
xdebug.mode=debug
xdebug.client_port=9003
# PhpStorm
监听 → 断点 → 访问页面
如果你用的是 Docker / LNMP / 宝塔 / 具体 PHP 版本,告诉我我可以直接给你对应配置。