Debian上PhpStorm远程调试配置指南
在Debian服务器上,通过APT包管理器安装Xdebug(确保PHP版本与Xdebug兼容):
sudo apt-get update
sudo apt-get install php-xdebug
安装完成后,Xdebug会自动集成到PHP环境中,但需进一步配置才能启用远程调试。
编辑PHP的全局配置文件(路径可通过php --ini
命令查看,常见为/etc/php/8.2/cli/php.ini
或/etc/php/8.2/apache2/php.ini
),在文件末尾添加以下配置:
[xdebug]
zend_extension=/usr/lib/php/20220829/xdebug.so # 根据实际Xdebug路径调整(通过`php -i | grep extension_dir`查看)
xdebug.mode=debug
xdebug.client_host=127.0.0.1 # 若PhpStorm与服务器在同一机器,用127.0.0.1;否则填PhpStorm所在机器的IP
xdebug.client_port=9003 # 默认端口,可与PhpStorm设置保持一致
xdebug.start_with_request=yes # 自动触发调试(可选:trigger/yes,trigger需通过浏览器扩展或GET参数启动)
xdebug.idekey=PHPSTORM # IDE标识,需与PhpStorm配置一致
保存后重启Web服务器(Apache/Nginx)使配置生效:
sudo systemctl restart apache2 # Apache
# 或
sudo systemctl restart nginx # Nginx
File > Settings > PHP
(或PhpStorm > Preferences > PHP
)。Add
,选择SSH Interpreter
。/usr/bin/php
),确认后点击Finish
。File > Settings > PHP > Servers
,点击+
添加新服务器。Debian-Remote
),设置Host
为服务器IP或域名,Port
为Web服务端口(如80/443)。Use path mappings
,将本地项目目录与远程服务器目录映射(例如:本地/home/user/project
→远程/var/www/html/project
)。Run > Edit Configurations
,点击+
添加PHP Remote Debug
配置。Debian-Remote
服务器,确认Port
与php.ini中的xdebug.client_port
一致(如9003)。OK
保存配置。Shift+F9
)开始监听调试连接。http://your-server-ip/project
),Xdebug会自动连接PhpStorm。Debug
模式,再访问页面。xdebug.client_port
端口被占用,修改为其他端口(如9007),并同步更新php.ini和PhpStorm配置。xdebug.client_port
端口的入站连接(如sudo ufw allow 9003/tcp
)。Servers
配置中的本地与远程目录映射是否正确,否则无法准确定位代码。php -m | grep xdebug
命令确认Xdebug扩展已加载,未加载则重启PHP-FPM或Web服务器。通过以上步骤,即可在Debian服务器上使用PhpStorm进行远程调试,实现本地与远程代码的无缝调试体验。