WSL2下 PhpStorm & Xdebug 调试环境配置
2020-11-03 15:43:00    32    0    0
ppps

1、编译安装xdebug扩展


PS.本人基于bt.cn一键安装的lnmp环境,其他环境请按需配置


1.1 安装xdebug扩展

直接使用宝塔面板安装

或者源码编译xdebug

cd ~
#git clone git://github.com/xdebug/xdebug.git
git clone https://hub.fastgit.org/xdebug/xdebug.git #FastGit.ORG加速通道
cd xdebug
/usr/local/php/bin/phpize
./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config
make && make install

或者pecl一键安装最新稳定版

pecl install xdebug

1.2 修改PHP配置

[xdebug]
zend_extension=/www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
#允许远程调试
xdebug.remote_enable=1
#如果配置该项就不需要配xdebug.remote_host,否则需要知道客户端公网IP
xdebug.remote_connect_back=1
#远程调试端口,此端口必须双向互通
xdebug.remote_port=9900
#可选,调试器的关键字
xdebug.idekey="PHPSTORM"

1.3 重启php-fpm


2、配置PhpStorm

PS.本人安装的是PhpStorm 2020.2.3,其他版本也是类似的

2.1 配置SFTP服务器与目录映射

2.1.1 SFTP配置

2.1.2 目录映射

2.2 配置远程PHP开发环境

2.2.1 配置远程PHP

2.2.2 配置远程PHP

PS.理论上,这里只要选择上面配置的WSL服务器(即:Ubuntu 20.04),其余会自动识别出来各项参数,无需配置(当然多版本php的情况还需要手动指定)

2.3 配置xdebug

2.3.1 指定xdebug端口

2.3.2 【可选】指定DBGp服务器配置

PS. 是否开启DBGp取决于是否需要多客户机远程调试,本文上面配置(1.2)仅考虑单客户机远程调试模式,所以此步骤可以跳过

引申阅读:

  1. https://www.cnblogs.com/jice/p/5064838.html
  2. https://en.wikipedia.org/wiki/DBGp

2.4 配置运行服务器

2.4.1 指定servers

2.4.2 新增运行配置

2.4.3 验证xdebug是否能连通

2.4.3 注意事项

1)上面配置的9900端口是否双向互通

2)这里是否能验证通过取决于2.1.2的目录映射是否正确,但是有些项目将站点url配置到非根目录的(例如:TP5是指向public目录下),就会报404错误

这里为了截图验证通过的界面,故意配错映射

 

2.5 开始调试

3、附录

3.1 官方文档

https://xdebug.org/docs/all

3.2 windows下的配置

[XDebug]
xdebug.profiler_output_dir="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir="D:\phpStudy\tmp\xdebug"
zend_extension="D:\phpStudy\php\php-7.2.17-nts\ext\php_xdebug.dll"
xdebug.remote_enable = On
xdebug.remote_autostart = On
xdebug.remote_handler=dbgp 
xdebug.remote_host=localhost
xdebug.remote_port = 9900
xdebug.idekey="PHPSTORM"
xdebug.collect_vars = On
xdebug.collect_return = On
xdebug.collect_params = On
xdebug.show_local_vars = On
xdebug.profiler_enable = On
xdebug.profiler_enable_trigger = On

 

 

 

Pre: No Post

Next: WSL2安装宝塔面板

32
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
目录