无法使用安装了自定义 PHP 7.2 且使用 Firefox VSCode 的 Vagrant 进行调试,VSCode 无法进入断点
Unable to debug using Vagrant with custom PHP 7.2 installed and VSCode using Firefox, VSCode fails to break into a breakpoint
在我的项目中,我在 Vagrant 运行 VM 上有以下 Xdebug 设置:
zend_extension=xdebug.so
xdebug.remote_host=10.0.2.2
debug.repomote_port=9000
xdebug.remote_enable=1
xdebug.max_nesting_level = 1000
xdebug.remote_log=/tmp/xdebug.log
虽然在 VSCode 我是这样设置的:
{
// 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": {
"/home/vagrant/code": "${workspaceRoot}",
}
}
]
}
xdebug 设置位于 inside 一个 vagrant vm 中,而 ide 在主机上。主机 Ip (10.0.2.2
) 是 provided 通过命令: netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
然后我使用 xdebug-helper
在 Firefox 上启用调试,设置如下:
但是我的IDE它无法在断点处停止执行。在调试它的同时,我打开了一个与 Vagrant 运行 VM:
的 shell 会话
vagrant up && vagrant ssh
然后我使用命令(在启用 VSCode 侦听 xdebug 之后)使用 TCP 协议测试与端口 9000 的反向连接:
nc -z -v 10.0.2.2 9000
命令本身显示消息:
Connection to 10.0.2.2 9000 port [tcp/*] succeeded!
还有我的 nginx.conf
说:
server {
listen 80;
server_name example.com;
root /home/vagrant/code;
index index.php index.html;
charset utf-8;
keepalive_timeout 65;
server_tokens off;
sendfile off;
access_log off;
error_log /var/log/nginx/error.log;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|svg)$ {
access_log off;
expires 30d;
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=3000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
location ~ /\.ht {
deny all;
}
}
而 Vagrantfile
如下:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box_version = "20180917.0.0"
config.vm.box_download_insecure = true
config.vm.provider "virtualbox" do |vb|
vb.name = "example-website"
vb.memory = 3072
vb.cpus = 2
vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end
config.vm.network "private_network", ip: "192.168.10.80"
config.vm.network "forwarded_port", guest: 80, host: 8090
config.vm.network "forwarded_port", guest: 22, host: 2922
config.vm.synced_folder "./.", "/home/vagrant/code"
config.vm.provision :shell, :path => "./machine/provision/provision-xenial64.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-hosts.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-docker.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-nginx.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-php.sh"
config.vm.provision :docker_compose, yml: "/home/vagrant/code/machine/docker_compose/cue.yml", run: "always"
end
此外,VSCode 实例也是一个 vscodium 构建,并且具有 felixfbecker.php-debug
插件。你知道为什么 VSCodium 打断点失败吗?
是否实际调用了代码?
有时由于前端错误,尤其是在 ajax 调用事件时,您的代码甚至可能根本不会调用。因此,首先确保您的代码确实被调用,然后尝试确定它是否是 xdebug 问题。
正如所见,正在执行从来宾到主机的 xdebug 连接。并且ip设置正确。因此,根本不调用具有断点的代码片段是相当合理的,因此 IDE 没有进入预期的断点。
在我的项目中,我在 Vagrant 运行 VM 上有以下 Xdebug 设置:
zend_extension=xdebug.so
xdebug.remote_host=10.0.2.2
debug.repomote_port=9000
xdebug.remote_enable=1
xdebug.max_nesting_level = 1000
xdebug.remote_log=/tmp/xdebug.log
虽然在 VSCode 我是这样设置的:
{
// 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": {
"/home/vagrant/code": "${workspaceRoot}",
}
}
]
}
xdebug 设置位于 inside 一个 vagrant vm 中,而 ide 在主机上。主机 Ip (10.0.2.2
) 是 provided 通过命令: netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
然后我使用 xdebug-helper
在 Firefox 上启用调试,设置如下:
但是我的IDE它无法在断点处停止执行。在调试它的同时,我打开了一个与 Vagrant 运行 VM:
的 shell 会话vagrant up && vagrant ssh
然后我使用命令(在启用 VSCode 侦听 xdebug 之后)使用 TCP 协议测试与端口 9000 的反向连接:
nc -z -v 10.0.2.2 9000
命令本身显示消息:
Connection to 10.0.2.2 9000 port [tcp/*] succeeded!
还有我的 nginx.conf
说:
server {
listen 80;
server_name example.com;
root /home/vagrant/code;
index index.php index.html;
charset utf-8;
keepalive_timeout 65;
server_tokens off;
sendfile off;
access_log off;
error_log /var/log/nginx/error.log;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|svg)$ {
access_log off;
expires 30d;
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=3000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
location ~ /\.ht {
deny all;
}
}
而 Vagrantfile
如下:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box_version = "20180917.0.0"
config.vm.box_download_insecure = true
config.vm.provider "virtualbox" do |vb|
vb.name = "example-website"
vb.memory = 3072
vb.cpus = 2
vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end
config.vm.network "private_network", ip: "192.168.10.80"
config.vm.network "forwarded_port", guest: 80, host: 8090
config.vm.network "forwarded_port", guest: 22, host: 2922
config.vm.synced_folder "./.", "/home/vagrant/code"
config.vm.provision :shell, :path => "./machine/provision/provision-xenial64.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-hosts.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-docker.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-nginx.sh"
config.vm.provision :shell, :path => "./machine/provision/provision-php.sh"
config.vm.provision :docker_compose, yml: "/home/vagrant/code/machine/docker_compose/cue.yml", run: "always"
end
此外,VSCode 实例也是一个 vscodium 构建,并且具有 felixfbecker.php-debug
插件。你知道为什么 VSCodium 打断点失败吗?
是否实际调用了代码?
有时由于前端错误,尤其是在 ajax 调用事件时,您的代码甚至可能根本不会调用。因此,首先确保您的代码确实被调用,然后尝试确定它是否是 xdebug 问题。
正如所见,正在执行从来宾到主机的 xdebug 连接。并且ip设置正确。因此,根本不调用具有断点的代码片段是相当合理的,因此 IDE 没有进入预期的断点。