PhpStorm 是 PHP 開發最強大的 IDE,配合 Xdebug 可實現斷點、單步執行、變數檢查、堆疊追蹤等專業除錯體驗。本文記錄 PHP 5.6 + PhpStorm 8.x 完整配置流程(新版大同小異)。
編輯 php.ini:
[xdebug]
zend_extension="D:/wamp/php-5.6.2-x64/ext/php_xdebug-2.2.5-5.6-vc11-x86_64.dll"
xdebug.remote_enable = On
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
重啟 Apache/Nginx,查看 phpinfo() 出現 Xdebug 區塊即成功。
或使用 phpStudy:其他選項 → PHP擴展設置 → XDEBUG 勾選即可。
File → Settings → Languages & Frameworks → PHP → Debug
Debug port = 9000(與 php.ini 一致)
File → Settings → Languages & Frameworks → PHP → Servers
Name: localhost, Host: localhost, Port: 80, Debugger: Xdebug
File → Settings → Languages & Frameworks → PHP → Debug → DBGp Proxy
IDE key: PHPSTORM, Host: localhost, Port: 80
Run → Edit Configurations → + → PHP Web Application
Server: 選擇剛建立的 localhost
Start URL: https://www.51open.pcom(你的本地域名)
Browser: 選擇 Chrome/Firefox
Shift + F9 啟動。xdebug.remote_connect_back=1、防火牆 9000 埠、IDE Key 一致。Path mappings(本地專案路徑 ↔ 伺服器絕對路徑)。Run → Start Listening for PHP Debug Connections(電話圖示變綠)。