標籤:style blog http color 使用 os io strong
說起來慚愧,自從開始使用Sublime Text之後,再也沒有debug過PHP的代碼,最近把debug的環境搭建了一下,在這裡記錄一下。
安裝XDebug
sudo apt-get install php5-xdebug
編輯xdebug.ini檔案,添加如下配置
xdebug.remote_enable=1xdebug.remote_handler=dbgpxdebug.remote_host=127.0.0.1xdebug.remote_port=9000xdebug.remote_log="/var/log/xdebug/xdebug.log"
重啟nginx
sudo /etc/init.d/nginx restart
然後在Sublime Text使用package control安裝xdebug client,用ctrl+shift+p調出搜尋方塊,輸入Package Control: 選中其中的Package Control: Install Package,輸入Xdebug client,找到xdebug client,安裝,安裝完成後要重啟Sublime。其操作如下:
要調試某一個項目,首先得把這個項目在sublime下儲存成一個project。
sublime->project->save project as ...
接下來設定項目
sublime->project->edit poject
設定檔類似以下內容:
{ "folders": [ { "follow_symlinks": true, "path": "." } ], "settings": { "xdebug": { "url": "http://my.local.website/", } }}
再在chrome中安裝Chrome Xdebug Helper擴充。在下載和安裝Chrome擴充後,你必須重新啟動瀏覽器。重新啟動後,你將看到在Chrome的地址欄的新表徵圖:
點擊它,將啟用/禁用調試。但是,我們首先需要調整擴充中使用 Sublime Text 的工作階段金鑰。
在Chrome中Tools > Extensions
開啟Xdebug helper options:
開啟調試方式也比較簡單,在想要加斷點的地方右鍵
xdebug->Add/Remove breakpoint
這樣項目在運行到本行的時候就會停止下來
然後開始調試,在功能表列選擇
tools->xdebug->start debugging(launch browser)
sublime會自動開啟瀏覽器,進入配置時寫的網站連結,進行調試。
調試中所用的功能可以在調試檔案中右鍵查看之。
快速鍵說明如下
Start/Stop debugging session
- Start Debugging - Ctrl+Shift+F9 or ?+Shift+F9
- Start Debugging (Launch Browser)
- Restart Session
- Stop Debugging - Ctrl+Shift+F10 or ?+Shift+F10
- Stop Debugging (Launch Browser)
- Stop Debugging (Close Windows)
Breakpoints
- Add/Remove Breakpoint - Ctrl+F8 or ?+F8
- Set Conditional Breakpoint - Shift+F8
- Clear Breakpoints
- Clear All Breakpoints
Watch expressions
- Set Watch Expression
- Edit Watch Expression
- Remove Watch Expression
- Clear Watch Expressions
Session commands
Continuation commands
- Run - Ctrl+Shift+F5 or ?+Shift+F5
- Run To Line
- Step Over - Ctrl+Shift+F6 or ?+Shift+F6
- Step Into - Ctrl+Shift+F7 or ?+Shift+F7
- Step Out - Ctrl+Shift+F8 or ?+Shift+F8
- Stop
- Detach
Other
- Restore Layout / Close Windows - Ctrl+Shift+F11 or ?+Shift+F11
- Settings - Default
- Settings - User
問題無法跟蹤斷點
這可能是xdebug連接埠被佔用,按Ctrl+`或者功能表列View->show Console查看錯誤資訊,有可能是xdebug連接埠已經被佔用的緣故。
在sublime xdebug中關閉調試,或者重啟sublime可以解決這個問題,如果還不行,可以修改連接埠號碼,如xdebug.ini中的連接埠號碼修改為為1000,在perferences->package settings->xdebug->setting-user檔案中加入如下內容:
{ "port": 10000}
弄好這個還是費了些時間~~
參考
Debug PHP with Sublime Text 2 and Xdebug on Ubuntu
用Xdebug和Sublime調試PHP代碼
Sublime配置XDebug