首页 > 技术文章 > vscode配置phpxdebug

wenbino 2019-09-07 09:52 原文

打debug还是很有必要的,以前嫌麻烦,现在觉得,通过debug可以看自己写的代码的执行的逻辑,更容易理清别人代码的逻辑。

 步骤:

  1. 下载phpdebug插件
  2. 查看自己的php版本信息,下载对应的debug版本
  3. 配置php.ini
  4.  配置 vscode中phpdebug配置(一般不用设置默认端口9000)

下载插件:

 

 

 2,查看自己的php版本所需的xdebug版本

打印phpinfo,随便写个方法在浏览器访问,就可以拿到phpinfo信息

当年还是新手的时候,自己搞了半天都不知道怎么获取phpinfo信息,简直想砸电脑

 

 

用自己配置的本地的域名,写个方法请求就可以了

 

  以下是phpinfo的信息

 

 

 

 根据自己的php版本下载xdebug,我的是php7.3 , 64位 ,线程安全版NTS

下载地址:https://xdebug.org/download.php

也可以复制phpinfo的信息检测自己需要的版本

phpinfo页面,浏览器查看源代码,复制正个页面元素信息

网址:https://xdebug.org/wizard.php

 

 

 

 

获得自己需要的版本的信息:

 

下载之后复制到php/ext下,ext是扩展文件

 

 

 

 

 

 

 

配置php.ini  通常在php/php.ini

 

 打开php.ini

在最后添加配置:

更新(2021年9月2号):下面是xdebug 2.xxxx版本的,现在是3.xxxx版本配置文件有些地方改变了写法

改变说明:PHP Debug - Visual Studio Marketplace

 

zend_extension: 填写自己的路径,后面添加自己的版本

2.xxxxx版本

 [XDebug]
zend_extension = D:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll    
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.romote_host=localhost
xdebug.remote_port=9000

3.xxxx版本配置

 

 [XDebug]
zend_extension = E:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug-3.0.4-7.3-vc15-nts-x86_64.dll
zend_extension=xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.remote_host=127.0.0.1
xdebug.remote_handler=dbgp
xdebug.idekey=vscode 

 

 

 

 

vscode中 phpdebug 配置:

 

 port: 默认9000对应php.ini中 

xdebug.remote_port=9000


 

 

在指定的地方打断点,请求如果成功一定会在指定的地方断住,如果无效就是没有配置成功

代码写的太烂打个码,笑哭

 

 

推荐阅读