1. 程式人生 > >PhpStorm+xdebug+postman除錯

PhpStorm+xdebug+postman除錯

 寫PHP時,一直用postman做測試,最近發現在測試過程中可以用xdebug來斷點除錯,比原來手動打exit或者die來斷點效率高多了。

   下面記錄下我自己從安裝到測試的全部詳細過程。我的執行環境是:windows+wamp

   一.配置wamp安裝目錄下的php.ini檔案

我的安裝目錄是:C:\wamp64\bin\apache\apache2.4.23\bin

 

zend_extension ="c:/wamp64/bin/php/php5.6.31/zend_ext/php_xdebug-2.5.5-5.6-vc11-x86_64.dll" xdebug.remote_enable = on xdebug.profiler_enable = off xdebug.profiler_enable_trigger = off xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir ="c:/wamp64/tmp" xdebug.show_local_vars=0 xdebug.remote_handler = dbgp ;設定xdebug的埠為9001 xdebug.remote_port = 9001 ;設定idekey xdebug.idekey="PHPSTORM"

二.在配置具體的專案之前,我們先配置好PhpStorm預設設定(default setting),避免每次建立專案都要進行的重複操作。

1.開啟PhpStorm,點選左上角File → Default Setting → Languages & Frameworks → PHP 如圖:

 

2.彈出interpreters視窗

 

3.新增頁面

 

4.正常情況下,配置好之後會顯示xdebug版本

 

5.設定xdebug埠號

 

6.設定 DBGp Proxy

 

 7.設定Servers,點選綠色的“+”配置一個新的Server  

  

三.接下來設定執行配置(Run → Edit Configuration),具體操作如下

   1.點選右上角,如圖

   

 2.設定預設的PHP web application配置

 

3.新建一個php web application

 

4.設定好斷點並開始除錯

 

 

注意:將此時瀏覽器的彈出框上面顯示的網址,複製到postman

 

5.除錯成功,按F9快捷鍵跳到下一個斷點如圖: