【已經(jīng)有作者發(fā)過(guò)類似的文章了,流程不是太詳細(xì),這里做個(gè)補(bǔ)充吧,也是自己的備忘!】
PHP 開(kāi)發(fā)的時(shí)候,頻繁的調(diào)試,總是打印感覺(jué)效率太低了,能不能像編譯型語(yǔ)言一樣斷點(diǎn)調(diào)試呢?當(dāng)然可以,只是需要進(jìn)行一些配置,稍顯麻煩。
一、準(zhǔn)備工具
- Chrome 瀏覽器
- Xdebug (Chrome 插件)
- Postman (Chrome 插件)
- PHP 集成開(kāi)發(fā)環(huán)境(如:phpStudy、wamp等)
- php_xdebug.dll 擴(kuò)展
- PhpStorm IDE
二、服務(wù)器配置
- 安裝 php_xdebug 擴(kuò)展后,php.ini 配置 XDebug 參數(shù),目錄參數(shù)配置成自己環(huán)境的,其他參數(shù)說(shuō)明自行百度或谷歌
[XDebug]
zend_extension="D:\phpStudy\php70n\ext\php_xdebug.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.profiler_output_name = "cache.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_mode = "req"
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port = 9010
xdebug.idekey= PHPSTROM
- 配置本地站點(diǎn)域名
示例域名: e.com,綁定 host。
127.0.0.1 e.com

示例:e.com
三、Xdebug 瀏覽器插件配置
-
IDE Key 配置為 PhpStorm
Xdebug 插件配置 -
Xdebug 插件開(kāi)啟調(diào)試
Xdebug 開(kāi)啟調(diào)試
四、PhpStorm IDE配置
-
設(shè)置 PHP 版本,選擇本地環(huán)境的 php 版本。
PHP 版本設(shè)置 -
XDebug 端口設(shè)置,這里設(shè)置成 php.ini 中 xdebug 配置的端口
XDebug 端口設(shè)置 -
DBGp proxy 設(shè)置
DBGp 代理設(shè)置 -
Servers 服務(wù)配置
Servers 配置,點(diǎn) + 號(hào)新增配置。注意勾選路徑匹配,并配置項(xiàng)目所在本地絕對(duì)路徑。
Servers 配置 -
編輯運(yùn)行/調(diào)試配置
Run/Debug 編輯
添加 Run/Debug 配置
添加 Run/Debug 配置 - PhpStorm 打開(kāi)請(qǐng)求監(jiān)聽(tīng)
開(kāi)啟請(qǐng)求監(jiān)聽(tīng)
![_]F9{FRS@L_8VIGE4KD@_9P.png](http://upload-images.jianshu.io/upload_images/3005871-fce8f295e3228eb4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
到此所有配置已經(jīng)完成。
五、訪問(wèn)站點(diǎn)調(diào)試。
-
瀏覽器訪問(wèn)調(diào)試
代碼中打幾個(gè)斷點(diǎn),瀏覽器中訪問(wèn) e.com。
Paste_Image.png -
Postman 中訪問(wèn)調(diào)試
Postman 中 post、put 等請(qǐng)求調(diào)試需要添加默認(rèn)參數(shù):XDEBUG_SESSION_START=PHPSTORM
post 請(qǐng)求調(diào)試
post 請(qǐng)求調(diào)試結(jié)果
如上多個(gè)站點(diǎn)調(diào)試則新增配置即可。










