确保远程Debian服务器已安装PHP(含php-cli
)和Web服务器(如Apache/Nginx),并具备sudo
权限用于安装扩展。
在远程服务器上执行以下命令安装Xdebug(根据PHP版本调整包名,如php8.2-xdebug
):
sudo apt update
sudo apt install php-xdebug # 或指定版本,如 php8.2-xdebug
安装完成后,Xdebug会自动加载,可通过php -m | grep xdebug
验证是否安装成功。
编辑远程服务器的PHP配置文件(通过php --ini
查找路径,通常为/etc/php/8.2/cli/php.ini
或/etc/php/8.2/apache2/php.ini
),在文件末尾添加以下配置:
[xdebug]
zend_extension=xdebug.so # 加载Xdebug扩展(路径可能为绝对路径,如/usr/lib/php/20220829/xdebug.so)
xdebug.mode=debug # 启用调试模式
xdebug.start_with_request=yes # 自动启动调试(或设为"trigger",通过GET/POST参数触发)
xdebug.client_host=你的本地IP # 本地机器的IP地址(如192.168.1.100,需确保服务器可访问)
xdebug.client_port=9003 # 调试端口(默认9003,需与PHPStorm一致)
xdebug.idekey=PHPSTORM # IDE标识符(需与PHPStorm配置一致)
修改后重启Web服务器使配置生效:
sudo systemctl restart apache2 # 或 sudo systemctl restart nginx
File > Settings > PHP
(或PhpStorm > Preferences > PHP
)。Add
,在弹出窗口中选择SSH Interpreter
。/usr/bin/php
),确认后点击OK
保存。File > Settings > Build, Execution, Deployment > Deployment
,点击+
添加新配置,选择SFTP
。Connection
标签页中,填写远程服务器的主机名、端口、用户名,选择认证方式(密码或密钥)。Test SFTP connection
验证连接,成功后点击OK
。Mappings
标签页,设置本地项目目录(如/Users/username/project
)与远程服务器目录(如/var/www/html/project
)的映射关系。Automatic upload
(可选),实现本地保存时自动同步到远程服务器。Run > Edit Configurations
,点击+
添加PHP Remote Debug
配置。Server
下拉菜单中选择之前配置的远程服务器(如Debian Server
),确保Port
(9003)与php.ini中的client_port
一致。OK
保存配置。Shift+F9
),此时图标变为绿色表示正在监听。?XDEBUG_SESSION_START=PHPSTORM
到URL(如http://example.com/index.php?XDEBUG_SESSION_START=PHPSTORM
)。xdebug.client_port
(如9003)的入站连接。xdebug.start_with_request=trigger
,需通过GET/POST参数(如XDEBUG_SESSION=PHPSTORM
)或Cookie触发调试。