1.安裝Xdebug
sudo apt-get install php5-xdebug
2.配置Xdebug
編輯/etc/php5/apache2/conf.d/xdebug.ini,加入
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_host = localhost
3.安裝vim插件DBGp
下載頁面: http://www.vim.org/scripts/script.php?script_id=1929
下載后放入plugins目錄中即可。
4.在瀏覽器中打開要調試的php頁面,在URL后加上?XDEBUG_SESSION_START=1參數(shù)
用vim打開此文件,用:Bp 設置斷點,然后安 F5 鍵,vi會提示 waiting for a new connection on port 9000 for 5 seconds… ,此時在5秒內刷新剛才那個頁面,即可在vim中看到調試界面。
如果出現(xiàn) , AttributeError("DbgProtocol instance has no attribute 'stop'", 則說明沒有配置成功,要么是 xdebug.remote_* 沒有配置好,要么是url尾部上沒有加入 ?XDEBUG_SESSION_START=1 ,要么是你沒有在5秒內刷新頁面 .
5.在獲取變量內容時,如果變量為 array ,那么默認只會顯出 (array) ,而不會顯示數(shù)組內的各元素,如果無法顯示數(shù)組元素內容,那么調試會遇到很多問題,因此可以根據(jù) debugger.vim 中的注釋,自行在 .vimrc 中加上如下一行:
let g:debuggerMaxDepth = 5
更多的配置,可以依次類推,都在debugger.vim中有所說明。
轉自http://lds2008.blogbus.com/logs/115127244.html