下面以 CentOS + PHPStorm + Xdebug 为例,说明如何配置 PHP 调试环境(最常用方案)。
假设:
# 查看 PHP 版本
php -v
# 安装(以 php 7.4 为例)
yum install -y php-pear php-devel gcc
pecl install xdebug
或(Remi 源):
yum install -y php74-php-xdebug
php --ini
[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=192.168.1.100 # 你的 PHPStorm 所在机器 IP
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
⚠️ 如果是 Docker / 虚拟机,client_host 要写 宿主机 IP
systemctl restart php-fpm
# 或
systemctl restart httpd
php -m | grep xdebug
File → Settings → PHP
Interpreter → 添加 CentOS 上的 php 路径
PHP → Debug
Debug port: 9003
PHP → Servers
Name: centos
Host: 项目域名或IP
Port: 80
Debugger: Xdebug
✔ Use path mappings
本地路径 ↔ CentOS 项目路径
PHPSTORMexport XDEBUG_TRIGGER=1
export XDEBUG_IDE_KEY=PHPSTORM
php index.php
firewall-cmd --add-port=9003/tcp --permanent
firewall-cmd --reload
setsebool -P httpd_can_network_connect 1
client_host=host.docker.internal如果你用的是:
可以告诉我,我给你对应配置。