整理人:pt007@vip.sina.com
1、准備環境
主機:window10
Phpstorm版本:2018.2.1 X64
Phpstudy版本:2018
PHP版本:5.6.27
php開發工具下載:https://www.php.cn/xiazai/gongju
2、安裝步驟
2.1 安裝Xdebug
本地的環境是用phpStudy搭建的,直接在phpStudy可以勾選Xdebug:
//打開並配置php.ini,保存后記得重啟phpstudy:
php.ini文件位置:E:\phpStudy2018\PHPTutorial\php\php-5.6.27-nts\
[XDebug]
zend_extension="E:\phpStudy2018\PHPTutorial\php\php-5.6.27-nts\ext\php_xdebug.dll"
xdebug.profiler_output_dir="E:\phpStudy2018\PHPTutorial\tmp\xdebug"
xdebug.trace_output_dir="E:\phpStudy2018\PHPTutorial\tmp\xdebug"
xdebug.remote_enable=1
xdebug.profiler_enable_trigger=0
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9100
xdebug.idekey="PHPSTORM"
xdebug.profiler_output_dir = "d:\tmp"
//驗證xdebug安裝是否成功:
2.2 配置phpstorm
2.2.1 配置phpstorm軟件的php版本
File->Settings
2.2.2 添加服務器
//可以配置一個公網IP,也可以是本機localhost:
2.2.3 Debug配置
//設置debug端口,這里設為9100,需要跟php.ini的配置一一對應:
2.2.4 DBGp Proxy配置
2.2.5 調試配置
2.3 chrome端xdebug-helper插件安裝
//chrome下的插件:xdebug-helper 需要翻牆安裝
https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=zh-CN
2.4 動態調試
1、首先啟動phpstudy2018
2、在程序里面打完斷點后,phpstorm開啟監聽:
3、Run->Debug 在彈出的窗口中選擇我們要動態調試的php程序:
如:index.php
//調試結果如下圖所示:
2.5 兩個坑
//pear安裝
如果你出現Cannot find PHPUnit in include path (.;C:\php5\pear),可能是pear和PHPUnit未安裝
安裝pear可以借助phpstudy,在其它選項,其它高級應用里面,安裝pear即可,也可以手動安裝,首先要找到go-pear.phar
E:\phpStudy2018\PHPTutorial\tools\pear
把go-pear.phar復制到php安裝目錄:
(E:\phpStudy2018\PHPTutorial\php\php-5.6.27-nts)
php go-pear.phar 執行一下就行了,安裝過程一路默認即可!
//PHPUnit安裝:
這個安裝走的坑也不少,最主要是找對版本,從官網拿下來了一張圖:
//php5.6下載phpunit5版本:phpunit-5.6.2.phar
請將下載的文件命名為phpunit.phar並考入目錄:
cd E:\phpStudy2018\PHPTutorial\php\php-5.6.27-nts,執行:
echo @php "%~dp0phpunit.phar" %* > phpunit.cmd
phpunit -version //會顯示phpunit版本的信息表示安裝成功
然后在phpstorm中找到test framework並設置為:
E:\phpStudy2018\PHPTutorial\php\php-5.6.27-nts\phpunit.phar