提及來慚愧,自從開始使用Sublime Text以後,再也沒有debug過PHP的代碼,最近把debug的環境搭建了一下,在這裏記錄一下。php
安裝XDebughtml
sudo apt-get install php5-xdebug
編輯xdebug.ini文件,添加以下配置nginx
xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 xdebug.remote_log="/var/log/xdebug/xdebug.log"
其中參數表明的含義以下:git
[Xdebug] ;load xdebug extension zend_extension_ts = path/tp/xdebug ;是否開啓自動跟蹤 xdebug.auto_trace = On ;是否開啓異常跟蹤 xdebug.show_exception_trace = On ;是否開啓遠程調試自動啓動 xdebug.remote_autostart = Off ;是否開啓遠程調試 xdebug.remote_enable = On ;容許調試的客戶端IP xdebug.remote_host=127.0.0.1 ;遠程調試的端口(默認9000) ;xdebug.remote_port=9000 ;調試插件dbgp xdebug.remote_handler=dbgp ;是否收集變量 xdebug.collect_vars = On ;是否收集返回值 xdebug.collect_return = On ;是否收集參數 xdebug.collect_params = On ;跟蹤輸出路徑 xdebug.trace_output_dir="path/to/xdebug/trace" ;是否開啓調試內容 xdebug.profiler_enable=On ;調試輸出路徑 xdebug.profiler_output_dir="path/to/xdebug/profiler"
重啓nginx和phpweb
sudo /etc/init.d/nginx restart sudo /etc/init.d/php-fpm restart
而後在Sublime Text使用package control安裝xdebug client,
用ctrl+shift+p調出搜索框,輸入Package Control: 選中其中的Package Control: Install Package,輸入Xdebug client,找到xdebug client,安裝,安裝完成後要重啓Sublime。其操做以下:chrome
要調試某一個項目,首先得把這個項目在sublime下保存成一個project。express
sublime->project->save project as ...
接下來配置項目ubuntu
sublime->project->edit poject
配置文件相似如下內容:sublime-text
{ "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會自動打開瀏覽器,進入配置時寫的網站連接,進行調試。
調試中所用的功能能夠在調試文件中右鍵查看之。
快捷鍵說明以下
這多是xdebug端口被佔用,按Ctrl+`或者菜單欄View->show Console查看錯誤信息,有多是xdebug端口已經被佔用的緣故。
在sublime xdebug中關閉調試,或者重啓sublime能夠解決這個問題,若是還不行,能夠修改端口號,如xdebug.ini中的端口號修改成爲1000,在perferences->package settings->xdebug->setting-user文件中加入以下內容:
{ "port": 10000 }
弄好這個仍是費了些時間~~
能夠再在perferences->package settings->xdebug->setting-user文件中加入以下內容:
"path_mapping": { "/absolute/path/to/file/on/server" : "/path/to/file/on/computer", "/var/www/htdocs/example/" : "C:/git/websites/example/" }