在Intellij IDEA下用X-debug除錯PHP

kingkoo發表於2018-04-24

用Intellij IDEA使用X-debug來除錯PHP,主要需要配置的部分有三個地方,分別為php.ini的配置,IDEA的配置和瀏覽器的配置,主要如下:

php.ini(wamp修改的是phpForApache.ini)的主要配置如下所示,關鍵引數根據實際情況可以修改:

 

xdebug 下載地址: https://xdebug.org/download.php

zend_extension  = "d:/wamp/bin/php/php7.1.16/zend_ext/php_xdebug-2.6.0-7.1-vc14-x86_64.dll"
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="D:/wamp/tmp"
xdebug.auto_trace = 0
xdebug.show_local_vars=0
xdebug.var_display_max_children=128 
xdebug.var_display_max_data=512 
xdebug.var_display_max_depth=5
xdebug.idekey=netbeans-xdebug
xdebug.remote_enable = On
;IDE所在機器IP
xdebug.remote_host=127.0.0.1 
;IDE監聽的埠號,用來和服務端的XDEBUG通訊用
xdebug.remote_port=9000 
xdebug.remote_handler=dbgp
; //這個要加上,否則無法除錯,這個配置的作用是當配置的遠端IDE的host和埠號有問題時,會通過請求頭讀取IDE的IP從而完成通訊
xdebug.remote_connect_back=1
xdebug.remote_autostart=0

  

配置好了,在CMD裡面輸入

php -m

如果能看到XDebug模組,說明開啟成功。

*: 值得注意的是,這裡需要確定好XDebug和PHP的對應版本

IDEA的配置如下:
進入File>Settings>PHP>Servers,這裡要填寫伺服器端的相關資訊,name填要除錯的主機名 (如:abc.com或者localhost等),host填(如:localhost或者abc.com等),port填 80,debugger選XDebug

進入File>Settings>PHP>Debug,看到XDebug選項卡,port填9000,其他預設

 

進入File>Settings>PHP>Debug>DBGp Proxy,IDE key 填 xdebug_info,host 填abc.com,port 填80

和php.ini的IDE_key要保持一致哦。。。。。、

最好有空可以建一個remote_debug檢查一下

 

最後就是瀏覽器設定了我下載的是xdebug Helper

 

相關文章