在 Debian 上使用 PhpStorm 调试的完整步骤
一 环境准备
php -v 可查看版本。二 安装与配置 Xdebug 3(推荐)
sudo apt-get install php-xdebug/etc/php/8.x/mods-available/xdebug.ini):
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.idekey=PHPSTORM
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=<你的IDE主机IP>
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.idekey=PHPSTORM
sudo systemctl restart apache2sudo systemctl restart php8.x-fpm(将 8.x 替换为实际版本)xdebug.mode=debug 与 client_host/client_port 与 IDE 通信,默认端口为 9003。三 PhpStorm 调试配置
File > Settings > Languages & Frameworks > PHP > CLI Interpreter,选择或添加 Debian 上的 PHP 可执行文件。File > Settings > Languages & Frameworks > PHP > Debug,将 Debug port 设为 9003(与 xdebug.client_port 一致)。File > Settings > Languages & Frameworks > PHP > Servers,新增服务器,填写 Name/Host/Port,将 Debugger 设为 Xdebug;若使用路径映射(例如容器/远程项目),在 Mappings 中设置本地项目路径与服务器路径对应关系。四 开始调试
Run > Edit Configurations,新建 PHP Script 或 PHP Remote Debug 配置,选择 CLI Interpreter,必要时设置 IDE Key;在代码中设置断点后点击调试运行,脚本会在断点处暂停。五 常见问题与排查
xdebug.client_port=9003 与 PhpStorm 一致;服务器与 IDE 主机之间的 防火墙/安全组 放行 9003/TCP;远程调试时 xdebug.client_host 必须是 IDE 主机可达的 IP。php -m | grep xdebug),xdebug.mode=debug 已设置,且 PhpStorm 处于 监听 状态;Web 调试需确保请求携带正确的 IDE Key(如使用 Xdebug Helper)。remote_enable 属于 Xdebug 2);请确认扩展版本与配置一致。xdebug.ini 后需重启 Apache 或 PHP-FPM 才会生效。