相对于其他编程语言,php的断点调试会稍微麻烦一点,毕竟其他语言基本都支持断点调试。
php的环境及断点调试搭建步骤如下:
- 安装phpstudy
去phpstudy官方网站下载,目前我下载的是最新版phpStudy v8.1版本(Windows)
2.设置php的xdebug
点击软件管理,这里php的环境为php7.4.3,默认为7.3.4(可删掉),点击扩展组件,
将xdbug调试组件打开,打开该开关,会将配置文件写入到php.ini文件中。
在phpstudy_pro\Extensions\php\php7.4.3nts的目录找到php.ini文件,找到如下代码:
[Xdebug]
xdebug.idekey=xdebug_info
zend_extension=D:/software/phpstudy_pro/Extensions/php/php7.4.3nts/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=On
xdebug.trace_output_dir=D:/software/phpstudy_pro/Extensions/php_log/php7.4.3nts.xdebug.trace
xdebug.profiler_enable=On
xdebug.profiler_output_dir=D:/software/phpstudy_pro/Extensions/php_log/php7.4.3nts.xdebug.profiler
xdebug.remote_enable=On
xdebug.remote_host=localhost
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
3、设置站点信息
在public文件夹中建立一个a.php,内容如下:
<?php
$a = 100;
echo $a;
phpinfo();
在浏览器访问:http://localhost/a.php,可以看到xdebug已经开启
4、设置Idea
在File->Settings下找到plugins,搜索php插件安装。
设置php的版本为7.4,设置CLI interpreter
设置xdebug的端口为9001,该端口为php.ini里面的端口
设置servers
设置dbgp proxy
重启一下apache,在浏览器访问http://localhost/a.php,此时会进入断点,至此php的断点调试已经搭建OK,可以愉快地进行php开发了。