如何在 Ubuntu 上使用 Valet 进行 php-debug 扩展 - 502 Bad Gateway

How to make php-debug extension with Valet on Ubuntu - 502 Bad Gateway

我正在调试一个简单的 index.php,但存在解析错误:

<?php

echo '<h1> Hello </h1>';

$value = 0;

if($value == 0){
    echo "true";
}else{
    echo "false"
}

我已经在我的 Ubuntu 上配置了 php-debug/Xdebug,设置是从不同的论坛读取的,但是它没有像我希望的那样工作。

它不加载局部变量,而是打开一个server.php。

Chrome 显示:502 错误网关。

有人遇到过这个错误吗?

安装细节

OS 描述:Ubuntu 16.04.4 LTS 发布:16.04 代号:xenial

由 Xdebug

解析的 phpinfo()
    Xdebug installed: 2.6.1
Server API: Command Line Interface
Windows: no
Zend Server: no
PHP Version: 7.2.9-1
Zend API nr: 320170718
PHP API nr: 20170718
Debug Build: no
Thread Safe Build: no
Configuration File Path: /etc/php/7.2/cli
Configuration File: /etc/php/7.2/cli/php.ini
Extensions directory: /usr/lib/php/20170718

Valet 版本 2.0.24 当前 Nginx 端口 (HTTP):80 当前 Nginx 端口 (HTTPS):443## 标题 ##

Xdebug.ini

zend_extension=/usr/lib/php/20170718/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9000 #if you want to change the port you can change

Launch.JSON

{ "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9000 }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port":
9000 } ] }

我为 Valet with Xdebug 和 VScode 发布的这个设置是正确的。它将为您的配置。我对 Xdebug 调试解析错误的期望是不正确的。调试前应删除解析错误。来自 Whosebug 用户 Amade 的有见地的评论如下:

Okay, in this case, you were doing it right in the beginning, just I think had somehow wrong expectations of xdebug with valet. It will open server.php from valet, since that's where the file with syntax error is required from. I don't think there is anything really you can do about it. But as you're working with VSCode, don't you get notifications of syntax errors in your panel? You can open it with ctrl+j