You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xdebug与NetBeans及Vagrant调试连接失败求助

Fixing Xdebug-NetBeans-Vagrant Connection Issues

Let’s walk through the key fixes for your problem—there are a couple of misconfigurations that are likely blocking your debug connection:

1. Correct Your NetBeans Project URL

The biggest issue here is your project URL pointing to 192.168.33.1:9000 instead of your Vagrant VM’s IP (192.168.33.10). NetBeans uses this URL to target the debug session, so it’s trying to connect to the wrong endpoint. Here’s how to fix it:

  • Right-click your project in NetBeans → Properties.
  • Navigate to Run Configuration.
  • Update the Project URL to match your VM’s web server address, e.g., http://192.168.33.10 (adjust the port if your web server uses something other than 80—note: port 9000 is for Xdebug, not your application).
  • Under Debugging, confirm the Debug Port is 9000 and Session ID is vagrant (this needs to match Xdebug’s idekey setting later).

2. Configure Xdebug on Your Vagrant VM

Xdebug needs to know how to connect back to your host machine (where NetBeans runs) to send debug data. Edit your xdebug.ini or php.ini file on the VM (typically found at /etc/php/<your-php-version>/mods-available/xdebug.ini) with these settings:

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=192.168.33.1  # This is your host machine's IP in the Vagrant host-only network
xdebug.client_port=9000
xdebug.idekey=vagrant  # Must match the Session ID in NetBeans
xdebug.log=/var/log/xdebug.log  # Optional, but critical for troubleshooting connection failures

After saving, restart your web server to apply changes:

sudo systemctl restart apache2  # Use `nginx` instead if that's your web server

3. Verify Network & Firewall Access

  • Test VM connectivity: Confirm you can access your app from your host browser using http://192.168.33.10—if this fails, check your Vagrantfile for host-only network misconfigurations.
  • Host firewall: Ensure your host machine allows incoming connections on port 9000 from 192.168.33.10. On Windows, use Windows Defender Firewall; on macOS/Linux, adjust ufw or iptables rules to permit traffic on port 9000.

4. Test the Debug Connection

  1. Set a breakpoint in your code (e.g., in index.php).
  2. Click the Debug button in NetBeans.
  3. NetBeans should open a browser window pointing to your app’s URL with an Xdebug parameter like ?XDEBUG_SESSION_START=vagrant.
  4. If your breakpoint triggers, you’re good to go! If not, check the xdebug.log file on the VM—it will show if Xdebug couldn’t connect to your host’s IP or port.

内容的提问来源于stack exchange,提问作者Danny Younes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:28:45