macOS PhpStorm Xdebug 使用详解

时间:2022-04-29
本文章向大家介绍macOS PhpStorm Xdebug 使用详解,主要内容包括场景、php-xdebug、配置、Chrome 插件、FireFox 插件、PhpStrom 配置、使用、相关链接、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

场景

  • LNMP 位于 macOS
  • LNMP 位于 Docker
  • LNMP 位于虚拟机中的 Docker

php-xdebug

安装

# php也是通过brew安装的

$ brew info php72-xdebug

$ brew install php72-xdebug

配置

/usr/local/etc/php/7.2/conf.d/ext-xdebug.ini

其他系统请替换为实际的路径

[xdebug]
# 必须使用绝对路径
zend_extension="/usr/local/opt/php71-xdebug/xdebug.so"
xdebug.remote_enable=1
#xdebug.remote_host=local004.khs1994.com
xdebug.remote_connect_back=1
xdebug.remote_port=9010
xdebug.remote_log=/tmp/xdebug-remote.log
xdebug.remote_handler=dbgp

Chrome 插件

https://github.com/mac-cain13/xdebug-helper-for-chrome

在选项中选择 PhpStrom

FireFox 插件

https://github.com/BrianGilbert/xdebug-helper-for-firefox

在选项中选择 PhpStrom

PhpStrom 配置

  • File -> Settings -> Languages&Frameworks -> PHP -> Debug ->Xdebug Debug port: 9010 三个选项全部勾选(必须与扩展中配置的端口一致)。

使用

  • 设置断点
  • 点击 电话 图标(run -> Start listening for PHP…)
  • 浏览器打开网址,点击 xdebug helper -》debug ,自动跳转到 IDE

相关链接