主要參考以下兩篇文章:
http://www.laokboke.net/2011/05/09/how-to-debug-php-using-xdebug/
http://my.oschina.net/u/1017069/blog/119963
1、工具:
Eclipse for PHP Developers http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliossr2
xampphttp://www.apachefriends.org/en/xampp-windows.html
2、Eclipse設置
下載eclipse for php developers後,解壓就可以使用了,打開後eclipse工具後就可以配置php和xdebug的相關信息了。
window->Preferences->php,
先配置php運行程序
配置運行環境
選擇php版本
配置服務器
配置xdebug
3、php.ini設定
在XAMPP中已經包含了Xdebug,所以只要稍微設置即可。
〇php.ini的修改:在文件的最後將以下內容【;】刪除
;zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
↓
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
;xdebug.remote_enable = 0
↓
xdebug.remote_enable = 1 *記得【0】要改成【1】
;xdebug.remote_host = "localhost"
↓
xdebug.remote_host = "localhost"
設定完成後重新啓動apache。可以在xampp控制中心裏啓動。
4.Eclipse中創建工程
重要:請把workspace建立在工作目錄:C:\xampp\htdocs 這樣可以省去很多麻煩,修改也容易。
建立在apache的工作目錄:C:\xampp\htdocs\PhpStudy
然後右鍵選擇工程,Debug Configurations。出現以下畫面,Server Debug選擇Xdebug。
然後File選項選擇你要debug的php文件
debug開始
中途會出現的一些問題。
1,apache啓動失敗
解決方法:查看那個進程佔用80或443端口然後將其關閉
2,debug開始時出現【Web Launch Already Running】錯誤
解決方法:因爲你已經啓動過php Server,所以先將其關閉,再重新啓動即可。