debian

Debian下phpstorm远程调试怎么设置

小樊
42
2025-05-12 17:24:26
栏目: 编程语言

在Debian系统下使用PhpStorm进行远程调试需要配置Xdebug和PhpStorm。以下是详细的步骤:

  1. 安装Xdebug: 在服务器上安装Xdebug扩展。可以使用以下命令:

    sudo apt-get install php-xdebug
    
  2. 配置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

  3. 重启Web服务器: 重启Apache或Nginx以应用更改:

    sudo systemctl restart apache2
    

    sudo systemctl restart nginx
    
  4. 配置PhpStorm

    • 打开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以保存设置。
  5. 设置断点: 在你的项目中设置断点,以便在调试时暂停执行。

  6. 开始调试

    • 在PhpStorm中,转到 Run -> Start Listening for PHP Debug Connections
    • 在浏览器中访问你的项目URL。当代码执行到断点时,PhpStorm将捕获并显示调试信息。
  7. 调试: 使用PhpStorm的调试工具栏来逐步执行代码、查看变量值等。

  8. 停止调试: 完成调试后,转到 Run -> Stop Listening for PHP Debug Connections以停止调试会话。

0
看了该问题的人还看了