如何使用xdebug调试php程序

1 由于我的是phpstudy集成环境,直接找到php.ini的位置:

D:\phpstudy_pro\Extensions\php\php7.3.9nts\php.ini

在文件尾部直接添加

[Xdebug]
zend_extension=D:/phpstudy_pro/Extensions/php/php7.0.9nts/ext/php_xdebug.dll
xdebug.idekey=phpstorm
xdebug.remote_enable = On
xdebug.remote_host=localhost
;xdebug.remote_port 默认值为9000,这里需要跟phpstorm配置一致,如果你用的是nginx+php-fpm,端口号最好换成9005,因为php-fpm默认使用的是9000
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.auto_trace = On
xdebug.remote_cookie_expire_time = 3600
max_execution_time=3600
max_input_time=3600
default_socket_timeout = 3600

进入Apache的配置文件httpd.conf进行修改

我的配置文件地址在
"D:\phpstudy_pro\Extensions\Apache2.4.39\conf\httpd.conf" #以自己文件的实际地址为准
可以直接在文件末尾进行添加

Timeout 3600 #将原有 Timeout 60 改为 Timeout 3600
FcgidIOTimeout 3600
FcgidIdleTimeout 3600
IPCConnectTimeout 3600
IPCCommTimeout 3600

如果用的是nginx,可以在nginx.conf 中添加

fastcgi_read_timeout 3600s;

  

需要添加到http段,直接添加到最外层会报错,
添加到location段不报错但是不生效.


保存退出后重启phpstudy环境

 

2 配置phpstorm2022

 

 

 如果你用的是nginx + php-fpm,最好Debug port里填写9005,9003因为php-fpm默认使用的是9000端口

3 安装chrome浏览器扩展:xdebug helper

除了应用市场下载,还可以在chrome浏览器地址栏输入chrome://extensions/,打开调试模式,然后把下载好的xdebug helper插件,

拖入界面安装。

安装好后:

 

4 开始调试:

在phpstorm上新建断点,打开调试侦听。

 

刷新浏览器网页,出现以下对勾,表示配置成功

此时可以用F7、F8、F9快捷键调试php程序了。

F7会进入调试时遇到的函数。

F8不会,直接运行下一行。

F9直接运行到下一个断点。

到最后可以切换到output选项卡查看程序的输出结果。

 

posted @ 2024-01-05 15:05  tochenwei  阅读(61)  评论(0编辑  收藏  举报