Visual Studio 扩展 PHP 调试未连接

我安装了 Visual Studio 代码 1.41.1 和 PHP 调试版本 - 1.13.0。


https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug


我在 Ubuntu 上运行 PHP Lamp 堆栈,我的 PHP 信息显示“xdebug xdebug support enabled - Version 2.9.0”


我的 PHP.ini 配置如下:


[XDebug]

zend_extension = /usr/lib/php/20170718/xdebug.so

xdebug.remote_enable = 1

xdebug.remote_autostart = 1

xdebug.remote_connect_back = 1

xdebug.remote_handler = dbgp

;xdebug.remote_host = 192.168.1.103

xdebug.remote_port=9000

xdebug.remote_log=/var/log/xdebug.log

我的launch.json如下:


{

    // Use IntelliSense to learn about possible attributes.

    // Hover to view descriptions of existing attributes.

    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

    "version": "0.2.0",

    "configurations": [

        {

            "name": "Listen for XDebug",

            "type": "php",

            "request": "launch",

            "port": 9000,

            "hostname": "192.168.1.23"

        },

        {

            "name": "Launch currently open script",

            "type": "php",

            "request": "launch",

            "program": "${file}",

            "cwd": "${fileDirname}",

            "port": 9000,

            "hostname": "192.168.1.23"

        }

    ]

}

我的服务器在 192.168.1.23 上运行,我的 ide 在 192.168.1.103 上运行。


日志文件似乎写得很慢——我不确定是哪个事件触发了日志中的事件。我怀疑它是直接从我的远程主机而不是通过 Visual Studio Code 访问网页。


我还将我的 Windows Defender 防火墙设置为在端口 9000 上打开。


根据评论进行编辑。192.168.1.103 是运行 Visual Studio 代码的 windows 10 机器的 IP 地址。该机器还运行版本 6.0.8 r130520 (Qt5.6.2),虚拟机的 IP 地址为 192.168.1.23。


我已将超时更新为 2000 毫秒。


我观察到,如果我关闭虚拟机,VSC 会尝试连接并继续尝试连接更长的时间。然后虚拟机启动,它会立即出错。这表明虚拟机阻塞了端口?


最后——是什么触发进入 xdebug.log。只是在网站上加载一个 PHP 文件会触发输出记录器吗?我问的原因是我无法辨别触发错误,但是在时间增量之间打开日志文件,即今天与昨晚,产生了各种错误?


机器和虚拟机在基于路由器的防火墙之后都是安全的,因此这不会是外部流量。


虚拟机按预期在 Windows 10 客户端计算机上运行。只是无法连接调试器。但是 PHP/MYSQL/APACHE 都运行正常。


哔哔one
浏览 181回答 2
2回答

哆啦的时光机

看起来其他东西已经在监听端口 9000,因此,VS 也无法打开相同的端口进行监听。这很可能是 PHP-FPM。要解决此问题,请在 php.ini 中设置以下内容:xdebug.remote_port=9003并将 VS 配置(两次)更改为相同的端口:"port": 9003,

三国纷争

该问题与防火墙阻止传入连接有关。为我解决了以下步骤:安装 UFW -sudo apt-get install ufwsudo ufw enablesudo ufw allow 9000/tcp在我的 Php.ini 中,我使用以下设置:[dDebug]zend_extension = /usr/lib/php/20190902/xdebug.soxdebug.remote_enable = 1xdebug.remote_autostart = 1xdebug.remote_connect_back = 1xdebug.remote_port=9000最后,我的启动 Json 有以下内容:{    // Use IntelliSense to learn about possible attributes.    // Hover to view descriptions of existing attributes.    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387    "version": "0.2.0",    "configurations": [        {            "name": "Listen for XDebug",            "type": "php",            "request": "launch",            "port": 9000,            "pathMappings": {                "/var/www/html/YourApp": "${workspaceRoot}/"              }        },        {            "name": "Launch currently open script",            "type": "php",            "request": "launch",            "program": "${file}",            "cwd": "${fileDirname}",            "port": 9000        }    ]}JSON 假设工作空间指向源数据的根,并且它没有隐藏在子文件夹中。最后,您将需要添加 UFW 规则以远程访问您的 Web 服务器,因为安装后这些默认情况下在 UFW 中不存在sudo ufw app listsudo ufw allow 'Apache Full'我还使用该方法从我的应用列表中添加了其他规则。我希望这可以帮助像我这样在新启动的 Ubuntu 18.04.4 VM 上努力连接到 xDebug 的人。
打开App,查看更多内容
随时随地看视频慕课网APP