[英]Xdebug for remote server not connecting
我希望使用不同計算機的團隊能夠在遠程服務器上調試 PHP,但我很難讓 Xdebug 在 NetBeans 7.0.1 中工作。 我嘗試了很多在線提示,但都無濟於事。
作為記錄,我已經在運行 WampServer 的 Windows 7 機器上成功地本地安裝了 Xdebug。 因此,我可以在 NetBeans 中使用斷點調試 PHP,前提是我將Project Properties->Run Configuration->Run As屬性設置為Local Web Site 。 但是,如上所述,我的目標是在遠程網站上的 NetBeans 中進行調試。
我的服務器是 Ubuntu 11.04 機器。 我已經使用http://www.xdebug.org/find-binary.php的輸出將正確的二進制文件放在機器上。 我已經修改了我能找到的所有php.ini
文件(在php5/apache2
和php5/cli
目錄中)以包含這些行:
zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
如果我檢查phpinfo.php
網頁,它會說:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans
所以 Xdebug 似乎安裝正確。 盡管如此,當我嘗試在 NetBeans 中進行調試時,我收到了無休止的狀態欄消息Waiting For Connection (netbeans-xdebug) 。 當我點擊停止按鈕時,我在 X 秒內沒有檢測到來自 xdebug 的連接。 原因可能是未安裝 xdebug 或未正確配置。
也許我在這里混淆了本地設置和服務器設置? 一個帖子說xdebug.remote_host
應該設置為運行 NetBeans 的機器的IP ,但我希望團隊能夠使用具有不同 IP 地址的機器進行調試。 問題可能是端口 9000,但我已經檢查過它沒有被阻止。
任何可以澄清這一點的幫助將不勝感激!
運行 PHP(和 XDebug)的服務器需要能夠連接到您的工作站/桌面。
因此,您需要通過告訴服務器連接到特定IP 地址( xdebug.remote_host
)或自動“連接回”( xdebug.remote_connect_back
)來相應地設置服務器。 不過,后者有一些安全隱患。 這些在手冊中有概述。
對我來說, xdebug.remote_connect_back = On
不起作用。 我所做的是在我的客戶端機器上設置 ssh 端口轉發。
遠程機器上的 xdebug 配置:
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
客戶端機器上的轉發端口:
ssh -g -N -lusername -R9000:127.0.0.1:9000 [remote.host.ip]
必須允許遠程機器上的 shell 訪問。
關鍵指令是這樣的:
xdebug.remote_connect_back = On
這允許 Web 服務器連接到任何要求調試會話的計算機。 這樣您就不必對 IP 地址進行硬編碼並且能夠共享 Xdebug。 該指令在早期版本中不存在,並且經常從教程和文檔中省略。
您還需要驗證每台客戶端計算機是否接受到端口 9000 ( xdebug.remote_port
) 的傳入連接。 這包括配置防火牆並確保調試器客戶端啟動並運行
摘要: https : //xdebug.org/docs/upgrade_guide
xdebug.
( remote_enable
| default_enable
| profiler_enable
| auto_trace
| coverage_enable
)xdebug.mode=debug
或使用develop
| coverage
| gcstats
| profile
xdebug.start_with_request=yes
xdebug.remote_autostart
被xdebug.mode=debug
替換為xdebug.start_with_request=yes
xdebug.remote_host
替換為xdebug.client_host
xdebug.remote_port
替換為xdebug.client_port
或在 IDE 設置中使用新的默認值(更多內容見下文)xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.idekey=myKey
xdebug.client_host=x.y.z.a
xdebug.remote_handler=dbgp
在哪里
xyza
= 您的 IDE 主機myKey
= 您在 IDE 中配置的密鑰remote_port
設置為9003
(xdebug 的新默認端口)或在上面的配置中將xdebug.client_port
設置為9000
以保持舊的默認值就我而言,這些命令幫助了我:
xdebug.remote_enable = On
xdebug.remote_autostart=1
注意:即使由於 'xdebug.remote_autostart=1' 不存在 GET/POST/COOKIE 變量,調試器也會工作
我在嘗試配置 docker 時遇到過幾次同樣的問題,在多次撓頭之后我意識到這是解決它的方法。 所以我決定把它放在這里作為我未來的自己的答案。
大多數情況下,Dockerfile 會將此語句添加到 php.ini 中:
xdebug.remote_connect_back = on
這會導致一切看起來都很好,但不知何故,PHP 風暴實際上沒有捕獲任何調試連接。 用以下內容替換上面的行立即為我解決了問題。
xdebug.remote_connect_back = 0
xdebug.remote_host = host.docker.internal
當然,之后你仍然需要運行: $ docker-compose down
$ docker-compose build
和$ docker-compose up -d
注意:在 Linux 上host.docker.internal
將不起作用。 您可以改用172.17.0.1
。 (注意不是 127.0.0.1,我一直以為是因為我有點不聽話)
感謝xdebug.remote_connect_back = On
服務器端 php.ini
此外,我必須為 Chrome 使用此插件才能在 PhpStorm 中啟動調試會話
您將需要設置:
xdebug.remote_host=192.168.1.104
192.168.1.104
是客戶端的 ip,您在其中使用 IDE
Brad 對 xdebug 3 的非常正確的回答; 謝謝...在我的情況下,我使用 Php7.3.13、Netbeans 8.2 和 IIS 10(eindia.com 是眾多網站之一)(瀏覽器是帶有 netbeans 擴展和 FF 的 Chrome)...並且沒有 Xampp、Wampp, Lampp ...然后我安裝了xdebug(使用向導)並配置如下:
[xDebug]
zend_extension = "C:\Program Files\PHP\v7.3\ext\php_xdebug-3.0.2-7.3-vc15-nts-x86_64.dll"
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler="dbgp"
xdebug.client_host="eindia.com"
;xdebug.remote_host=192.168.1.5
;xdebug.remote_connect_back=1
xdebug.client_port=9003
;xdebug.remote_mode=req
xdebug.idekey="netbeans-xdebug"
它的工作就像魅力一樣。
如果您使用的是 xdebug 3,您需要知道一些變量被重命名。 閱讀: https : //xdebug.org/docs/upgrade_guide
php.ini 配置對我有用:
[xdebug]
xdebug.mode=debug
zend_extension="C:/wamp64/bin/php/php7.4.26/ext/php_xdebug.dll"
xdebug.idekey=PHPSTORM
xdebug.client_host= "localhost"
xdebug.client_port=9003
您要啟動哪個頁面擴展來開始調試? 我記得我瘋了,度過了不眠之夜,XDebug 的所有設置都很順利。 問題是我不是從.PHP
開始,而是從.HTML
開始。
如果您嘗試使用.PHP
文件啟動調試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.