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

能否转发Xdebug连接?跨虚拟主机调试隧道搭建求助

Can Xdebug connect to local PhpStorm when H1's CLI triggers a cURL request to H2?

Absolutely, this scenario is totally feasible! The key is to override Xdebug's default behavior of connecting back to the request initiator (H1) and force it to target your local Windows machine instead. Here's a step-by-step breakdown to make it work:

1. Adjust H2's Xdebug Configuration (php.ini)

Since H2 is handling the incoming cURL request from H1, we need to modify its PHP settings to point Xdebug directly to your local Windows IP. Open H2's php.ini (make sure you edit the one used by its web server, not CLI unless specifically needed) and update these values:

xdebug.remote_enable = 1
xdebug.remote_host = YOUR_LOCAL_WINDOWS_LAN_IP  # e.g., 192.168.1.100
xdebug.remote_port = 9000  # Match your PhpStorm Xdebug port
xdebug.remote_autostart = 1  # Auto-trigger debugging without manual session parameters
xdebug.remote_connect_back = 0  # Critical: Disable auto-connect to the request initiator (H1)

After saving, restart H2's web server (Apache/Nginx) to apply the changes.

2. Configure Local Firewall Access

Make sure your Windows 10 firewall allows incoming connections on port 9000 (or whatever port you set for Xdebug). Create an inbound rule to permit traffic from your Linux VM's IP range to this port—this ensures H2's Xdebug can reach your local machine.

3. Set Up PhpStorm for Remote Debugging

  • Enable Debug Listening: Click the "Start Listening for PHP Debug Connections" icon (looks like a telephone) in PhpStorm's toolbar to activate debugging mode.
  • Configure Server Mapping:
    1. Go to File > Settings > Languages & Frameworks > PHP > Servers
    2. Add a new server:
      • Name: Any descriptive name (e.g., "H2 Remote Server")
      • Host: H2's domain or IP address (the exact value you use in your cURL request)
      • Port: H2's web port (80 for HTTP, 443 for HTTPS)
      • Debugger: Select "Xdebug"
      • Check "Use path mappings", then map H2's Symfony project root directory (e.g., /var/www/h2) to the corresponding directory on your local Windows machine. This ensures PhpStorm can match remote code to your local files for accurate breakpoint handling.

4. Test the Setup

  1. Set a breakpoint in H2's Symfony code (e.g., inside a controller method that handles the cURL request endpoint).
  2. On H1, run your CLI command that triggers the cURL request to H2 (e.g., curl http://h2.example.com/api/your-target-endpoint).
  3. PhpStorm should immediately catch the debugging session, and you can step through H2's code as if you were triggering the request directly from Postman.

Quick Checks to Avoid Issues

  • Verify your Linux VM can reach your local Windows IP: Run ping YOUR_LOCAL_WINDOWS_IP from the VM to confirm connectivity.
  • Double-check H2's Xdebug settings: Create a phpinfo.php file in H2's web root and load it in a browser to ensure the modified php.ini values are active.
  • Since you're using PHP 7.2, Xdebug 2.9.x is the latest compatible version—stick to the config parameters above (Xdebug 3 uses different syntax, which isn't relevant here).

内容的提问来源于stack exchange,提问作者Christian Rosick

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 16:22:55