【问题标题】:vagrant + xdebug + vscode流浪者 + xdebug + vscode
【发布时间】:2022-01-26 08:46:36
【问题描述】:
  • OS X 版本 12.1
  • 流浪者版本 2.2.19
  • 流浪机器有ubuntu 16.04
  • php 7.4
  • xdebug v3.0.2
  • nginx 服务器

我把xdebug.ini的配置改成:

date.timezone = "Europe/Berlin"
short_open_tag = Off
xdebug.idekey=VSCODE
xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_port=9003
xdebug.client_host = 10.254.254.254
xdebug.max_nesting_level = 512
xdebug.log_level=10
xdebug.connect_timeout_ms=600
xdebug.log=/var/log/xdebug/xdebug33.log
xdebug.show_error_trace=true

在 VS 代码中 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": 9003,
            "pathMappings": {
              "/var/www/":"../../../projects",
            },
            "log":true
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }
    ]
}

这是开始调试后的日志输出:

[24787] Log opened at 2021-12-27 09:48:14.979149
[24787] [Step Debug] INFO: Connecting to configured address/port: 10.254.254.254:9003.
[24787] [Step Debug] ERR: Time-out connecting to debugging client, waited: 600 ms. Tried: 10.254.254.254:9003 (through xdebug.client_host/xdebug.client_port) :-(
[24787] Log closed at 2021-12-27 09:48:15.606819

我尝试将此端口添加到 vagrant 文件中,如下所示:


Vagrant.configure(2) do |config|
  config.vm.box_url = "file:///Users/test/ubuntu16_php7.4_vagrantbox"
  config.vm.box = "baazzbox"
  config.vm.provider "virtualbox" do |v|
    v.memory = 5120
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate//var/www","1"]
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/var/www","1"]
  end

  #config.vm.box = "ubuntu/xenial64"
  config.vm.network "private_network", ip: "192.168.33.33"
  config.vm.network "forwarded_port", guest: 9003, host: 9003 

  config.vm.synced_folder "../", "/var/www"

  config.vm.provision "fix-no-tty", type: "shell" do |s|
    s.privileged = false
    s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
  end

  config.vm.provision "file", source: "root", destination: "~"
  config.vm.provision :shell, path: "setup_vagrant.sh"
  config.vm.box_check_update = false
end


我尝试添加和删除这一行:

  config.vm.network "forwarded_port", guest: 9003, host: 9003 

但它具有相同的输出。

我也重启服务如下:

sudo service php7.4-fpm reload
sudo systemctl restart nginx.service 

【问题讨论】:

    标签: macos visual-studio-code vagrant xdebug-3


    【解决方案1】:

    终于找到问题了,

    • 将 vagrant 时区更改为与主机时区相同
    • 服务器 xdebug 配置 .ini 文件更改为:
    xdebug.idekey=VSCODE
    xdebug.mode=debug
    xdebug.start_with_request=yes
    xdebug.remote_autorestart = 1
    xdebug.client_port=9003
    xdebug.discover_client_host=1
    xdebug.max_nesting_level = 512
    xdebug.log_level=10
    xdebug.connect_timeout_ms=600
    xdebug.log=/var/log/xdebug/xdebug33.log
    xdebug.show_error_trace=true
    

    注意此配置与 xdebug V3 相关

    • 在vagrant文​​件中,将端口80添加为forwrded_port就这样
    
    Vagrant.configure(2) do |config|
      config.vm.box_url = "file:///Users/toqaabbas/projects/theqar_vagrant/ubuntu16_php7.4_vagrantbox"
      config.vm.box = "baazbox"
      config.vm.provider "virtualbox" do |v|
        v.memory = 5120
        v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate//var/www","1"]
        v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/var/www","1"]
      end
    
      #config.vm.box = "ubuntu/xenial64"
      config.vm.network "private_network", ip: "192.168.33.33"
      config.vm.network "forwarded_port", guest: 80, host: 80 
      config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Asia/Amman /etc/localtime", run: "always"
    
      config.vm.synced_folder "../", "/var/www"
    
      config.vm.provision "fix-no-tty", type: "shell" do |s|
        s.privileged = false
        s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
      end
    
      config.vm.provision "file", source: "root", destination: "~"
      config.vm.provision :shell, path: "setup_vagrant.sh"
      config.vm.box_check_update = false
    end
    
    

    然后运行 ​​"vagrant reload" 重新构建 vagrant

    • 最后把 lanuch.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": 9003,
                "pathMappings": {
                    "/var/www" : "/Users/myusername/projects"
                },
            },
            {
                "name": "Launch currently open script",
                "type": "php",
                "request": "launch",
                "program": "${file}",
                "cwd": "${fileDirname}",
                "port": 9003
            }
        ]
    }
    

    最重要的部分是“pathMappings”的正确位置

    终于成功了:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-04
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      相关资源
      最近更新 更多