在Debian系统下使用PhpStorm进行远程调试需要配置Xdebug和PhpStorm。以下是详细的步骤:
安装Xdebug: 在服务器上安装Xdebug扩展。可以使用以下命令:
sudo apt-get install php-xdebug
配置php.ini:
编辑php.ini文件(通常位于/etc/php/7.x/cli/php.ini
或/etc/php.ini
),添加以下配置:
[xdebug]
zend_extension=/usr/lib/php/20190902/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
。
重启Web服务器: 重启Apache或Nginx以应用更改:
sudo systemctl restart apache2
或
sudo systemctl restart nginx
配置PhpStorm:
File
-> Settings
-> Languages & Frameworks
-> PHP
。CLI Interpreter
部分,点击齿轮图标,然后选择Add
。SSH Interpreter
,然后输入你的Debian服务器的IP地址、用户名和密码。Interpreter
部分,选择Path to PHP executable
,这应该是你的服务器上的PHP可执行文件路径,例如/usr/bin/php
。Additional Options
部分,添加以下参数:-xdebug.start_with_request=yes -xdebug.client_host=127.0.0.1 -xdebug.client_port=9003
Finish
以保存设置。设置断点: 在你的项目中设置断点,以便在调试时暂停执行。
开始调试:
Run
-> Start Listening for PHP Debug Connections
。调试: 使用PhpStorm的调试工具栏来逐步执行代码、查看变量值等。
停止调试:
完成调试后,转到 Run
-> Stop Listening for PHP Debug Connections
以停止调试会话。