這回使用visual studio code折騰php代碼的調試,又是一頓折騰,無論如何都進不了斷點。好在就要放棄使用visual studio code工具的時候,折騰好了,汗~
這里把步驟記錄下來:
1、安裝一站式php工具wampserver
我安裝的是最新的3.1.3 64bit的版本,這個版本內置了4個版本的php,默認使用的是php 5.6.35。如果需要調試php,必須要使用php 7.0以上的版本,這個可能是跟我使用的visual studio code的php插件有關。這里切換到php 7的版本。
2、安裝並配置xdebug參數
wampserver默認是內置了xdebug的,不過需要修改一下xdebug的參數。
找到wampserver的托盤工具,左鍵點擊-》PHP->PHP Settings,勾選xdebug.remote_enable,這一項
然后,左鍵點擊-》PHP->php.ini文件,發現會在php.ini文件自動生成如下內容:
; XDEBUG Extension [xdebug] zend_extension ="D:/Program/wamp64/bin/php/php7.0.29/zend_ext/php_xdebug-2.6.0-7.0-vc14-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 ="D:/Program/wamp64/tmp" xdebug.show_local_vars=0
需要添加一行內容,修改后的內容為:
; XDEBUG Extension [xdebug] zend_extension ="D:/Program/wamp64/bin/php/php7.0.29/zend_ext/php_xdebug-2.6.0-7.0-vc14-x86_64.dll" xdebug.remote_enable = On xdebug.remote_autostart=on xdebug.profiler_enable = off xdebug.profiler_enable_trigger = Off xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir ="D:/Program/wamp64/tmp" xdebug.show_local_vars=0
紅色的部分是我添加的內容,一直進不了斷點,是因為我這句標紅的內容沒有加,xdebug.remote_autostart參數並不能像xdebug.remote_enable參數一樣可以通過菜單開啟,汗~~
修改以后,記得重啟apache服務
3、安裝visual studio code的php插件
如圖所示,添加
PHP IntelliSense和PHP Debug兩個插件
這兩個插件都需要配置php的路徑,菜單:文件-》首選項-》設置
用戶設置,我修改為:
{
"php.executablePath": "D:\\Program\\wamp64\\bin\\php\\php7.0.29\\php.exe",
"php.validate.executablePath": "D:\\Program\\wamp64\\bin\\php\\php7.0.29\\php.exe"
}
我這里引用的是wampserver內置的php的版本,注意要跟上面啟用的php的版本保持一致。
4、Visual Studio Code啟用調試
到調試這一欄,添加php的調試,並且啟用調試
那么在代碼中添加斷點,運行代碼,就可以進行php代碼的調試了!