1. 程式人生 > >本地環境phpStorm+XDebug配置和斷點除錯

本地環境phpStorm+XDebug配置和斷點除錯

安裝環境:XAMPP;phpStorm; windows 7 64bit。

XAMPP、phpStorm 都直接安裝在了D盤根目錄,9999m目錄建在D:\xampp\htocts下,即目錄工程資料夾路徑為D:\xampp\htocts\9999m。在phpStorm>File>open,找到9999m,點選確定,載入9999m到了phpStorm(安裝環境路徑根據需要自行更改,後面的配置內容也類似)。

1.      開始伺服器端配置:安裝好XAMPP,停止apache服務(注意,如果直接退出XAMPP,是不會停止apache的)。

2.      在安裝目錄下找到php.ini,類似於D:\xampp\php\php.ini,並開啟。

3.      找到被註釋掉的專案(去掉前面的?)並按如下設定:

[XDebug]

==============原始碼

xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.profiler_output_name = "cache.out.%t-%s"
xdebug.remote_enable = 1


xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
;zend_extension="D:\phpStudy\php53n\ext\xdebug.dll"

==============改後

xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir ="D:\phpStudy\tmp\xdebug"


xdebug.profiler_output_name = "cache.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
zend_extension="D:\phpStudy\php53n\ext\xdebug.dll"
xdebug.idekey= PHPSTROM

====================轉載的

zend_extension = "D:\xampp\php\ext\php_xdebug.dll"

xdebug.profiler_append = 0

xdebug.profiler_enable = 1

xdebug.profiler_enable_trigger = 0

xdebug.profiler_output_dir = "D:\xampp\tmp"

xdebug.profiler_output_name = "cachegrind.out.%t-%s"

xdebug.remote_enable = on

xdebug.remote_handler = "dbgp"

xdebug.remote_host = "127.0.0.1"

xdebug.trace_output_dir = "D:\xampp\tmp"

xdebug.idekey= PHPSTROM   

最初的設定是這樣的:圖2

 

;的意思是被註釋掉了,所以要先去掉;號;

然後開啟xdebug.remote_enable = on;

還要增加xdebug.idekey= PHPSTROM。

其中remote_host 是指除錯客戶端的地址,即IDE所在的IP,同理remote_port 是客戶端的埠,這兩項在遠端除錯的情況下注意修改,遠端的時候最終改為:

[XDebug]

zend_extension = "D:\xampp\php\ext\php_xdebug.dll"

xdebug.profiler_append = 0

xdebug.profiler_enable = 1

xdebug.profiler_enable_trigger = 0

xdebug.profiler_output_dir = "D:\xampp\tmp"

xdebug.profiler_output_name = "cachegrind.out.%t-%s"

xdebug.remote_enable = 1

xdebug.remote_handler = "dbgp"

xdebug.remote_mode = "req"

xdebug.remote_port = 9000

4.      儲存檔案,重新啟動apache檢查是否成功開啟了xdebug服務。

 一種方法為在CMD裡輸入D:\xampp\php\php.exe -m 看到XDebug,說明成功開啟XDebug。

另一種方法為瀏覽器開啟localhost,找到phpinfo()點選開啟配置情況,查詢xdebug項,找到了說明xdebug配置成功。

 

至此,伺服器端配置完畢。

5.      下面是客戶端除錯。開啟phpStorm,進入File>Settings>PHP(檔案-設定-語言和框架-php),這裡要interpreter瀏覽,填D:\xampp\php\php.exe,自動識別版本。

6.      進入File>Settings>PHP>Servers,這裡要填寫伺服器端的相關資訊,name填localhost,

  ,host填localhost,port填80,debugger選XDebug。圖7 是自定義的虛擬域名。

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

 

8.      進入File>Settings>PHP>Debug>DBGp Proxy,IDE key 填 PHPSTORM,host 填localhost,port填9000,點OK退出設定。圖9

 

9.      進入Run> Debug configurations,點+號,Server選填localhost,start url 是在http://localhost的基礎上再加上去,如加上 9999m,就形成http://localhost/9999m.

以圖中藍色地址為參考, Browse 填chrome,點OK退出設定。圖10

 

點OK退出設定之後,phpstorm執行按鈕旁邊自動填充localhost,且執行按鈕由灰色被啟用成為綠色。如果start url填的是http://localhost,沒有填寫9999m,則當點選phpstorm執行按鈕,瀏覽器進入預設地址http://localhost,沒辦法直接訪問http://localhost/9999m

10.   chrome瀏覽器連結配置。找到對應的外掛,chrome的為phpstrom IDE Support chrome.crx,自己下載然後拖動檔案到chrome設定>擴充套件程式。

 

Chrome右上角增加了JB圖示即為成功安裝外掛。

11.   在phpStorm裡開啟監聽,就是一個電話一樣的按鈕,點選變為綠色,在程式程式碼點前點選,設定程式段點,點選綠色的debug爬蟲按鈕,chrome瀏覽器開啟xdebug頁,phpStorm出現debug視窗,並獲取到variables值,即為看到下面的debug資訊,說明成功配置。圖13

12 斷點除錯

 

 通過點選紅框中的位置設定和取消斷點

 

大功告成!!!