美文网首页
Mac Nginx PhpStorm XDebug配置

Mac Nginx PhpStorm XDebug配置

作者: 王兴岭 | 来源:发表于2020-03-29 20:40 被阅读0次

设备

系统: macOS Mojave
php版本: PHP 7.1.31
服务器: Nginx
浏览器: Chrome
框架: ThinkCMF

配置

注意:本教程是在假设系统没有安装xdebug

1. 安装xdebug

下载匹配php版本的xdebug
使用wizard分析phpinfo并生成安装xdebug的步骤

$php -i > info.txt

将info.txt中内容复制粘贴到wizard

image.png
点击Analyse my phpinfo() output按钮生成分析报告
Summary
  • Xdebug installed: 2.9.4
  • Server API: Command Line Interface
  • Windows: no
  • Zend Server: no
  • PHP Version: 7.1.31
  • Zend API nr: 320160303
  • PHP API nr: 20160303
  • Debug Build: no
  • Thread Safe Build: no
  • OPcache Loaded: yes
  • Configuration File Path: /usr/local/php5/lib
  • Configuration File: /usr/local/php5/lib/php.ini
  • Extensions directory: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303
You're already running the latest Xdebug version

But here are the instructions anyway:

  1. Download xdebug-2.9.4.tgz

  2. Install the pre-requisites for compiling PHP extensions.
    On your Mac, we only support installations with 'homebrew', and brew install php && brew install autoconf should pull in the right packages.

  3. Unpack the downloaded file with tar -xvzf xdebug-2.9.4.tgz

  4. Run: cd xdebug-2.9.4

  5. Run: phpize (See the FAQ if you don't have phpize).

    As part of its output it should show:

    <pre data-original-code="Configuring for:
    ...
    Zend Module Api No: 20160303
    Zend Extension Api No: 320160303" data-snippet-id="ext.27c1781585f912b698dc674da4d5b2f3" data-snippet-saved="false" data-codota-status="done" style="line-height: 1.5em; font-family: "IBM Plex Mono"; padding: 20px; background: rgb(238, 238, 238); display: block; font-size: 14px; overflow: auto;">Configuring for:
    ...
    Zend Module Api No: 20160303
    Zend Extension Api No: 320160303</pre>

    If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.

  6. Run: ./configure

  7. Run: make

  8. Run:cp modules/xdebug.so /usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303

  9. Update /usr/local/php5/lib/php.ini and change the line
    zend_extension = /usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
    Make sure thatzend_extension = /usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so is below the line for OPcache.

按照上面的步骤安装xdebug就行了

2. 配置xdebug, 在步骤1中生成的 info.txt有如下内容

Loaded Configuration File => /usr/local/php5/lib/php.ini
Scan this dir for additional .ini files => /usr/local/php5/php.d

所以配置xdebug有两种方式,直接在php.ini配置, 或者在php.d目录下创建一个单独的xdebug-extension.ini,

[xdebug]
zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.remote_enable=On
xdebug.remote_handler=dbgp
xdebug.default_enable=on
xdebug.remote_autostart=on
xdebug.remote_port=9020
xdebug.idekey=PHPSTORM
xdebug.remote_host=localhost
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_name=xdebug-profile-cachegrind.out-%H-%R
xdebug.var_display_max_children = 128
xdebug.var_display_max_data = 512
xdebug.var_display_max_depth = 3
xdebug.remote_log=/var/tmp/xdebug.log

remote_enable, remote_port,idekey,remote_host必须配置,其他的参数自己根据自己的实际需求进行配置就行了
remote_port端口的配置要注意一定要是一个未被使用的端口,否则xdebug配置可能不会生效
根据我上面的配置,需要坚持9020是否已经被使用了,

sudo lsof -i:9020

如果控制台没有任何输出,就说明可以使用.否则要么换一个端口,要么把被占用的端口释放掉.

3. PhpStorm 配置

  • 配置xdebug端口, 和.ini配置文件中的remote_port一致
Preferences -> Language & Frameworks ->Debug -> xdebug port : 9020
image.png
  • 配置DBGp Proxy
Preferences -> Language & Frameworks -> Debug -> DBGp Proxy

IDE key : 和php.ini文件中的xdebug.idekey一致, Host: 本地测试填写localhost, Port: php web服务运行的端口8082 根据自己的项目端口进行调整

image.png

4. 测试 debug

  • Enable listening for PHP Debug Connection


    image.png
* 查看9020监听端口是否开启
sudo lsof -i:9020

如果输出

COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
phpstorm 2454 lemo-wu   77u  IPv4 0x636ff71e9c8d8ad9      0t0  TCP *:tambora (LISTEN)

表示监听已经启动

  • 请求一个接口测试
    http://localhost:8082/api/demo
    然后PhpStorm就会弹出一个弹出框
    image.png
    点击Accept.
    image.png
    就会在断点处停下来了,就可以进行debug调试了.
    如果要关闭PhpStorm debug调试,只要再次点击
    image.png
    变成
    image.png
    就行了

引用

wizard生成xdebug安装步骤

相关文章

网友评论

      本文标题:Mac Nginx PhpStorm XDebug配置

      本文链接:https://www.haomeiwen.com/subject/vpouuhtx.html