在我的项目中,我在运行VM的Vagrant上具有以下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}",
}
}
]
}
当ide在主机上时,xdebug设置位于流浪汉vm中。主机IP(10.0.2.2
)通过以下命令提供: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无法突破到断点吗?
答案 0 :(得分:0)
代码实际上被调用了吗?
有时由于前端错误,尤其是在ajax调用事件上,您的代码甚至根本没有被调用。因此,请首先确保您的代码已被实际调用,然后尝试确定是否是xdebug问题。
因此可以看出,正在执行从访客到主机的xdebug上的连接。并且ip设置正确。因此,完全不具有断点的那段代码是合理的,因此IDE不会中断到预期的断点。