PHP代码审计环境配置教程
1.vscode的配置
-
安装插件 code runner PHP debug
2.PHPstudy配置
软件管理 — PHP设置 — 开启XDebug调试组件
开启XDebug调试组件之后,可以看到php.ini文件底部多了如下几行:
[Xdebug] zend_extension=D:/CStools/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll xdebug.collect_params=1 xdebug.collect_return=1 xdebug.auto_trace=Off xdebug.trace_output_dir=D:/CStools/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.trace xdebug.profiler_enable=Off xdebug.profiler_output_dir=D:/CStools/phpstudy_pro/Extensions/php_log/php7.3.4nts.xdebug.profiler xdebug.remote_enable=On xdebug.remote_host=localhost xdebug.remote_port=9000 xdebug.remote_handler=dbgp
首先配置文件(ini)中xdebug.remote_enable=Off需要手动改为On
随后在配置文件底部加入如下三行:
xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_port = 9000
最后,将phpstudy的php.exe文件加入到环境变量path里面
php -v 命令验证成功:
C:Usersdahez>php -v
PHP 7.3.4 (cli) (built: Apr 2 2019 21:57:22) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
3.使用xdebug调试代码
创建json文件后,注意json文件的端口号要和phpstudy配置的xdebug端口号一致
launch.json文件:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"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,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9000,
"serverReadyAction": {
"pattern": "Development Server \(http://localhost:([0-9]+)\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
phpstudy配置的xdebug端口号:(这里和上文的port端口号一定要保持一致)
插入断点F5调试成功:
