phpstorm远程调试环境搭建

phpstorm + xdebug远程调试环境搭建

phpstorm远程调试环境搭建

搭建工具需求:phpstorm+phpstudy

过程说明

首先是在phpstudy搭建一个网站,然后在扩展里选上xdebug:

image-20250301152550757

可以写一个phpinfo()回显页面,然后全部赋值粘贴拿到xdebug官方页面来寻求适配的xdebug版本:

image-20250301152948395

下载给的文件,然后将其改名为php_xdebug.dll并放在ext目录下。

再然后修改一下php.ini内容,这里走了很多坑,如下即可:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[Xdebug]
zend_extension=D:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll
xdebug.log=D:/phpstudy_pro/xdebug.log
xdebug.mode=debug;
xdebug.remote_handler="dbgp"
xdebug.start_with_request = yes
xdebug.discover_client_host = yes
xdebug.client_host = localhost
xdebug.client_port = 62649
xdebug.idekey="PHPSTORM"

注意一下xdebug2和xdebug3的区别,我这里是xdebug3。然后就是配置phpstorm了:

在设置的debug部分:

image-20250301153502453

一定要开启侦听,然后这里的端口需要与前面配置文件中的client_port相同。

然后配置DBGp代理:

image-20250301153638510

然后配置一个服务器:

image-20250301153728266

这里的主机可以随便填,但是端口就需要和phpstudy上的一样。然后编辑配置:

image-20250301153809082

加一个PHP网页:

image-20250301153923621

可以点击验证来验证一下:

image-20250301155312836

然后打一个断点就可以开始调试了:

image-20250301155353243

调试超时解决方法:

1.php.ini需要设置xdebug和mac_execution_time等,来增加等待时间:

1
2
3
4
5
# 超时时间改大一点
xdebug.remote_cookie_expire_time = 7200
max_execution_time=7200
max_input_time=7200
default_socket_timeout = 7200

2.修改apache的配置文件,这里就贴一下我加的一些配置:

修改httpd.conf:将下面这行的前面的注释去掉:

1
Include conf/extra/httpd-default.conf

然后添加如下一行:

1
Include conf/extra/httpd-fcgid.conf

并且在最后加上如下内容

1
2
3
4
5
6
# 超时时间改大一点
Timeout 7200
FcgidIOTimeout 7200
FcgidIdleTimeout 7200
IPCConnectTimeout 7200
IPCCommTimeout 7200

然后在conf\extra\httpd-default.conf里修改,修改文档内容如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 7200

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 0

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 7200

最后在apache\conf\extra目录下新建一个httpd-fcgid.conf文件,加入如下内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
ProcessLifeTime 7200
FcgidIOTimeout 7200
FcgidConnectTimeout 7200
FcgidOutputBufferSize 128
FcgidMaxRequestsPerProcess 1000
FcgidMinProcessesPerClass 0 
FcgidMaxProcesses 16 
FcgidMaxRequestLen 268435456   
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
IPCConnectTimeout 7200
IPCCommTimeout 7200
FcgidIdleTimeout 7200
FcgidBusyTimeout 60000
FcgidBusyScanInterval 120
FcgidInitialEnv PHPRC "D:\phpstudy_pro\Extensions\php\php7.4.3nts"
AddHandler fcgid-script .php

php路径自己修改,然后如果还想改时间更长的话就是改上面的7200这个数字。

最后重启一下apache即可,应该就是可以了。

易坑点

几个比较重要的点吧,也有些是这里想着重说明的:

  • 每次修改php.ini文件,都是需要重启一次服务的。直接在phpstudy上的apache哪里重启就行了。
  • 如果有几个环境,比如phpstudy上创建了几个网站,搞混了就比较麻烦,在验证这里我是卡了很久的。如果按照前面的操作,在最后验证的那一步出现了什么端口繁忙等等问题,关掉其他网站,然后重启电脑再次尝试。

参考文章:

https://www.cnblogs.com/gaorenyusi/p/18213773

https://blog.csdn.net/kelleo/article/details/135215408

https://blog.csdn.net/weixin_43888304/article/details/120802226

https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_autostart

Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计