我們做開發的都知道單步調試必不可少,但是對於php來說不像其他語言一樣方便單步調試,下面我就教大家怎麼利用xdebug對php進行單步調試
首先到https://xdebug.org/wizard.php這個網站測試當前php版本時候那個xdebug .
在終端裏輸入php -i 然後把輸出的信息複製到上面的網址上。然後把對應的xdebug下載到本地
一windows:
1.VSCode安裝擴展PHP Debug.2.安裝XDebug.
3.1)假如沒有用phpStudy軟件需要設置php.ini
把php_xdebug-2.3.2-5.4-vc9-nts.dll拷貝到php/ext目錄下。 (php_xdebug-2.3.2-5.4-vc9-nts.dll配置文件可以找我要)然後再配置php.ini
zend_extension=ext/php_xdebug-2.3.2-5.4-vc9-nts.dll
[xdebug]
xdebug.remote_enable=1
2).安裝phpStudy的話,php_xdebug軟件自帶了,只需要配置php.inizend_extension=ext/php_xdebug-2.3.2-5.4-vc9-nts.dll
5.配置Vscode.
按F1打開命令,輸入setting選擇用戶設置。打開默認設置。配置可執行的php.exe文件
// Place your settings in this file to overwrite the default settings
{
// 指向可執行的 php。
"php.validate.executablePath": "C:/php54/php.exe"
}
5.launch.json
{
"version": "0.2.0",
"configurations":
[
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
6.ctrl+shift+d打開調試。
終端php調試 set xdebug_config="idekey=1 remote_autostart=1"
二Mac:
找到php安裝目錄:
php -ini
which php
php —version
php —ini
whereis php
sudo vi /usr/local/etc/php/5.5/php.ini
1.安裝brew
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local —strip 1
2.跟新brew
sudo brew update
3.安裝xdebug
sudo brew install homebrew/php/php55-xdebug
4.ext-xdebug.ini文件中配置
[xdebug]
zend_extension="/usr/local/opt/php55-xdebug/xdebug.so"
xdebug.remote_enable=1
5.setting:
配置php可執行文件:
"php.validate.executablePath": "/usr/local/bin/php"
brew search xdebug
技術鏈接:https://my.oschina.net/youdian/blog/753201