温馨提示×

centos phpstorm调试怎样设

小樊
47
2026-09-21 04:49:36
栏目: 编程语言

下面以 CentOS + PHPStorm + Xdebug 为例,说明如何配置 PHP 调试环境(最常用方案)。


一、环境准备

假设:

  • CentOS 7/8
  • PHP 已安装(php-cli / php-fpm)
  • PHPStorm 已安装(本地或远程)

1. 安装 Xdebug

# 查看 PHP 版本
php -v

# 安装(以 php 7.4 为例)
yum install -y php-pear php-devel gcc
pecl install xdebug

或(Remi 源):

yum install -y php74-php-xdebug

二、配置 Xdebug(php.ini)

1. 找到 php.ini

php --ini

2. 添加 Xdebug 配置

[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

3. 重启 PHP

systemctl restart php-fpm
# 或
systemctl restart httpd

4. 验证

php -m | grep xdebug

三、PHPStorm 配置

1. 设置 PHP 解释器

File → Settings → PHP
Interpreter → 添加 CentOS 上的 php 路径

2. Debug 端口

PHP → Debug
Debug port: 9003

3. Server 配置

PHP → Servers
Name: centos
Host: 项目域名或IP
Port: 80
Debugger: Xdebug
✔ Use path mappings
本地路径 ↔ CentOS 项目路径

四、浏览器 / 手动触发调试

方式一:浏览器插件

  • 安装 Xdebug Helper
  • IDE Key 设为 PHPSTORM
  • 开启 Debug

方式二:命令行

export XDEBUG_TRIGGER=1
export XDEBUG_IDE_KEY=PHPSTORM
php index.php

五、开始调试

  1. PHPStorm 打断点
  2. 点击 电话图标(Start Listening)
  3. 浏览器访问页面
  4. 自动进入断点

六、常见问题

连不上?

  • 防火墙
firewall-cmd --add-port=9003/tcp --permanent
firewall-cmd --reload
  • SELinux
setsebool -P httpd_can_network_connect 1

Docker 场景?

  • client_host=host.docker.internal
  • 或宿主机 IP

如果你用的是:

  • Docker
  • PHP 8+
  • CLI 调试
  • 远程服务器

可以告诉我,我给你对应配置。

0 踩