【问题标题】:Can't trigger Xdebug break in PhpStorm using Laravel on Nginx无法在 Nginx 上使用 Laravel 在 PhpStorm 中触发 Xdebug 中断
【发布时间】:2021-03-14 15:09:48
【问题描述】:

我一直试图让 Xdebug 与在 nginx 上的 php8.0-fpm 上运行的 Laravel 一起工作,但没有成功。

我正在使用 PhpStorm 触发断点,但似乎连xdebug_break() 都没有触发。

这些是我所有的配置,如果需要我也可以在评论中发phpinfo()

nginx:

server {
    listen 80;
    server_name dashboard.local;
    root /var/www/dashboard/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

php 配置:

PHP 8.0.0 (cli) (built: Nov 27 2020 12:26:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
    with Xdebug v3.0.0, Copyright (c) 2002-2020, by Derick Rethans
➜  ~ php-config -v
Usage: /usr/bin/php-config [OPTION]
Options:
  --prefix            [/usr]
  --includes          [-I/usr/include/php/20200930 -I/usr/include/php/20200930/main -I/usr/include/php/20200930/TSRM -I/usr/include/php/20200930/Zend -I/usr/include/php/20200930/ext -I/usr/include/php/20200930/ext/date/lib ]
  --ldflags           [-L/usr/lib/php/20200930 ]
  --libs              [-lcrypt   -largon2 -lresolv -lcrypt -lutil -lrt -lm -ldl  -lxml2 -lssl -lcrypto -lpcre2-8 -lz -lsodium -largon2 -lcrypt ]
  --extension-dir     [/usr/lib/php/20200930]
  --include-dir       [/usr/include/php/20200930]
  --man-dir           [/usr/share/man]
  --php-binary        [/usr/bin/php8.0]
  --php-sapis         [cli fpm ]
  --phpapi            [20200930]
  --ini-path          [/etc/php/8.0/cli]
  --ini-dir           [/etc/php/8.0/cli/conf.d]
  --configure-options [--includedir=/usr/include --mandir=/usr/share/man --infodir=/usr/share/info --disable-silent-rules --libdir=/usr/lib/x86_64-linux-gnu --libexecdir=/usr/lib/x86_64-linux-gnu --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-cli --disable-cgi --disable-phpdbg --with-config-file-path=/etc/php/8.0/cli --with-config-file-scan-dir=/etc/php/8.0/cli/conf.d --build=x86_64-linux-gnu --host=x86_64-linux-gnu --config-cache --cache-file=/build/php8.0-xu5Vr1/php8.0-8.0.0/config.cache --libdir=${prefix}/lib/php --libexecdir=${prefix}/lib/php --datadir=${prefix}/share/php/8.0 --program-suffix=8.0 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --disable-all --disable-debug --disable-rpath --disable-static --with-pic --with-layout=GNU --without-pear --enable-filter --with-openssl --with-password-argon2=/usr --with-external-pcre --enable-hash --with-mhash=/usr --with-libxml --enable-session --with-sodium --with-system-tzdata --with-zlib=/usr --with-zlib-dir=/usr --enable-dtrace --enable-pcntl --with-libedit=shared,/usr build_alias=x86_64-linux-gnu host_alias=x86_64-linux-gnu CFLAGS=-g -O2 -fdebug-prefix-map=/build/php8.0-xu5Vr1/php8.0-8.0.0=. -fstack-protector-strong -Wformat -Werror=format-security -O2 -Wall -pedantic -fsigned-char -fno-strict-aliasing -g]
  --version           [8.0.0]
  --vernum            [80000]

xdebug.ini (/etc/php/8.0/mods-available/xdebug.ini):

zend_extension = /usr/lib/php/20200930/xdebug.so
; zend_extension = xdebug.so
xdebug.remote_enable = 1
xdebug.remote_mode = req
xdebug.remote_host = http//dashboard.local
xdebug.remote_port = 9009
xdebug.remoce_connect_back = on
xdebug.remote_handler = "dbgp"
xdebug.remote_autostart = 0
xdebug.idekey = PHPSTORM
xdebug.remote_autostart = 0
xdebug.remote_log = "/var/log/xdebug/xdebug.log"
xdebug.show_error_trace = 1
xdebug.start_with_request = yes

PhpStorm:

谢谢你:)

编辑 1:

我已经降级到 php 7.4 和 Xdebug 2.9.8,但似乎我仍然无法从 Xdebug 得到任何响应。根据LazyOne 的要求,这是我拥有的所有配置。

php 配置:

Usage: /usr/bin/php-config [OPTION]
Options:
  --prefix            [/usr]
  --includes          [-I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib ]
  --ldflags           [-L/usr/lib/php/20190902 ]
  --libs              [-lcrypt   -largon2 -lresolv -lcrypt -lrt -lm -ldl  -lxml2 -lssl -lcrypto -lpcre2-8 -lz -lsodium -lcrypt -largon2 -lcrypt ]
  --extension-dir     [/usr/lib/php/20190902]
  --include-dir       [/usr/include/php/20190902]
  --man-dir           [/usr/share/man]
  --php-binary        [/usr/bin/php7.4]
  --php-sapis         [apache2handler cgi cli fpm ]
  --phpapi            [20190902]
  --ini-path          [/etc/php/7.4/cli]
  --ini-dir           [/etc/php/7.4/cli/conf.d]
  --configure-options [--includedir=/usr/include --mandir=/usr/share/man --infodir=/usr/share/info --disable-silent-rules --libdir=/usr/lib/x86_64-linux-gnu --libexecdir=/usr/lib/x86_64-linux-gnu --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-cli --disable-cgi --disable-phpdbg --with-config-file-path=/etc/php/7.4/cli --with-config-file-scan-dir=/etc/php/7.4/cli/conf.d --build=x86_64-linux-gnu --host=x86_64-linux-gnu --config-cache --cache-file=/build/php7.4-efh2kh/php7.4-7.4.13/config.cache --libdir=${prefix}/lib/php --libexecdir=${prefix}/lib/php --datadir=${prefix}/share/php/7.4 --program-suffix=7.4 --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --disable-all --disable-debug --disable-rpath --disable-static --with-pic --with-layout=GNU --without-pear --enable-filter --with-openssl --with-password-argon2=/usr --with-external-pcre --enable-hash --with-mhash=/usr --with-libxml --enable-session --with-sodium --with-system-tzdata --with-zlib=/usr --with-zlib-dir=/usr --enable-dtrace --enable-pcntl --with-libedit=shared,/usr build_alias=x86_64-linux-gnu host_alias=x86_64-linux-gnu CFLAGS=-g -O2 -fdebug-prefix-map=/build/php7.4-efh2kh/php7.4-7.4.13=. -fstack-protector-strong -Wformat -Werror=format-security -O2 -Wall -pedantic -fsigned-char -fno-strict-aliasing -g]
  --version           [7.4.13]
  --vernum            [70413]

来自 phpinfo() 的 xdebug 部分:

xdebug 日志:

PHPStorm 配置:

【问题讨论】:

  • 您正在使用 XDEBUG 3 和旧参数。建议你check out the upgrade guide我整个下午都在做同样的事情
  • 你有 Xdebug v3 .. 但继续使用 Xdebug v2 配置参数。请通过xdebug.org/docs/upgrade_guide 调整您的设置。 Xdebug v3 使用与 Xdebug v2 不同的配置参数。
  • "但似乎连xdebug_break() 都没有被触发。" 顺便说一句——这个函数现在的工作方式与 Xdebug v2 中的有点不同——它不再启动新的调试会话,它现在只能用作程序断点,仅此而已。
  • 感谢您的帮助,我已经尝试使用升级指南中描述的参数,但仍然无法使其工作。如果我不明白,我会降级到 v2。
  • @VladMB 显示您现在所拥有的:1) 您尝试使用的配置 (php.ini),2) 实际/实时配置是什么(来自 phpinfo() 输出的 Xdebug 部分或xdebug_info() 捕获的方式与您尝试调试的方式相同。3) Xdebug 日志必须说明什么 4) PhpStorm 配置是什么。 Xdebug 3 在 2020.2.4 和 2020.3 RC 中都可以正常工作

标签: php ubuntu nginx phpstorm xdebug


【解决方案1】:

在与LazyOne 进行会话后,我们发现我没有为 Xdebug 使用正确的模式,因为我需要将其设置为 debug。以前我将它设置为develop,这意味着开发辅助,我认为它也包含 Step Debugger。

这是最终配置的最终结果(对于 Xdebug 3.0.1):

zend_extension=xdebug.so
xdebug.mode=develop,debug
xdebug.client_port=9009
xdebug.client_host=127.0.0.1

这使我能够触发断点,前提是我在 Chrome 中有 Xdebug Helper 扩展,或者在发出请求时提供了 XDEBUG_SESSION_START 参数(在我的情况下 = PHPSTORM)。

再次感谢您的帮助,LazyOne

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 2013-09-29
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 2017-05-16
    • 1970-01-01
    • 2014-05-28
    相关资源
    最近更新 更多