centos

centos环境下phpstorm远程调试方法

小樊
52
2025-09-05 18:34:59
栏目: 编程语言

以下是CentOS环境下使用PhpStorm远程调试PHP代码的步骤:

  1. 安装Xdebug扩展

    • 通过PECL安装:
      sudo yum install php-devel gcc make
      sudo pecl install xdebug
      
    • 编辑php.ini,添加以下配置(需根据实际路径调整):
      zend_extension=/usr/lib64/php/modules/xdebug.so
      xdebug.remote_enable=1
      xdebug.remote_host=<PhpStorm机器IP>  # 或使用remote_connect_back=1自动获取
      xdebug.remote_port=9003  # 与PhpStorm配置一致
      xdebug.idekey=PHPSTORM
      xdebug.remote_autostart=1
      
    • 重启PHP-FPM:
      sudo systemctl restart php-fpm
      
  2. 配置PhpStorm

    • 设置PHP解释器
      File > Settings > Languages & Frameworks > PHP > CLI Interpreter,选择服务器PHP路径(如/usr/sbin/php-fpm)。
    • 添加远程服务器
      Run > Edit Configurations > + > PHP Remote Debug,填写服务器名称、IP、端口(与xdebug.remote_port一致),选择对应的PHP解释器。
    • 配置路径映射
      在服务器配置中勾选Use path mappings,将本地项目路径映射到服务器路径(如/var/www/html)。
  3. 启动调试

    • 在PhpStorm中点击Start Listening for PHP Debug Connections(虫子图标)。
    • 浏览器访问配置的URL(如http://服务器IP:9003),触发断点后进入调试模式。
  4. 可选:SSH隧道(跨网络使用)

    • 本地执行:
      ssh -R 9003:localhost:9003 user@服务器IP
      
    • 在PhpStorm的Deployment中勾选Use SSH tunnel,配置对应端口。

注意事项

0
看了该问题的人还看了