2025-04-01
PHP
jetbrains、xdebug2
57

一、下载安装

1.xdebug 安装
适用版本:PHP7.1(xdebug-2.9.8)
下载地址:https://xdebug.org/download
检测地址:https://xdebug.org/wizard,根据 phpinfo() 找到对应 PHP 版本的 XDEBUG 并下载安装
cd /usr/local/download

wget https://www.xdebug.org/files/xdebug-2.9.8.tgz
tar -zxvf xdebug-2.9.8.tgz

cd /usr/local/download/xdebug-2.9.8

/usr/local/software/php7.1/bin/phpize
./configure --with-php-config=/usr/local/software/php7.1/bin/php-config
make clean
make && make install
2.php 配置文件
vim /usr/local/software/php7.1/etc/php.ini

# 在配置文件末尾添加
[XDebug]
zend_extension=xdebug.so
xdebug.remote_handler=dbgp
xdebug.profiler_output_dir=/www/log/php/xdebug_php71.log
xdebug.idekey=PHPSTORM
xdebug.remote_port=9003
xdebug.remote_enable=1
xdebug.remote_host=192.168.6.52 # 宿主机 IPv4 地址,非默认网关

# 重启 PHP-FPM
systemctl restart php71-fpm.service

二、Phpstorm 配置

1.settings 设置
File -> Settings -> PHP:
1.点击 ClI Interpreter 右边按钮进入配置页面;
2.点击左上角 + 号,选择 From Docker,Vagrant,VM… ;
3.再选择 Vagrant,Vagrant Instance Folder 为 Vagrantfile 所在目录,如:C:\Users\jdzor;
4.PHP interpreter path 为虚拟机内 php 所在路径,如:/usr/bin/php71;
配置成功后页面会显示 php 版本和 xdebug 版本等信息

File -> Settings -> PHP -> Debug,在 Xdebug -> Debug port 填入 php.ini 文件中端口.
如:Debug port:9003

File -> Settings -> PHP -> Debug -> DBGp Proxy,填写 IDE key(php.ini文件), Host(虚拟机 IP,ifconfig eth1), Port(php.ini文件)。
如:IDE key:PHPSTORM, Host:192.168.56.30, Port:9003

File -> Settings -> PHP -> Servers,选择左边 + 号,新建一个 Server,Host 填写虚拟机IP(ifconfig eth1),勾选 Use path mappings (select if ...),其中 Absolute path on the server 选择虚拟机中项目地址,地址不存在时可以手动输入。
如:Name:local24.api.vco.com, Host:192.168.56.30, Port:80, Debugger:Xdebug, Project files: E:\jdzor-2025\xxx => /www/jdzor-2025/xxx
2.debug configuration
点击右上方 Add Configurations…,弹出页面后点击左上角 + 号,选择 PHP Remote Debug,填入 Server 和 IDE key,然后开启 debug 模式,打开监听。
如:Server:local24.api.vco.com, IDE key:PHPSTORM

三、其他设置

1.Apipost
Cookie 管理器中打开开关,并添加域名 local24.api.vco.com,并修改默认 Cookie 值如下:
XDEBUG_SESSION=PHPSTORM;Path=/;Domain=local24.api.vco.com;Expires=Fri, 14 Nov 2099 03:11:13 GMT
2.服务器超时配置
修改 nginx.conf
# 服务端在读取客户端发送的请求时设置的超时时间
client_header_timeout 1200;
client_body_timeout   1200;
reset_timedout_connection on;

# 设置服务端传送回应包时的超时时间
send_timeout  1200;
修改 php.ini
max_execution_time = 1200
max_input_time = 1200
修改 php-fpm.conf
request_terminate_timeout = 1200
3.debug 面板说明
**左侧**
绿色三角形:Resume Program,表示將继续执行,直到下一个中断点停止
红色方形:Stop,表示中断当前程序调试

**上方**
第一个图形示:Step Over,跳过当前函数
第二个图形示:Step Into,进入当前函数內部的程序(相当于观察程序一步一步执行)
第三个图形示:Force Step Into,強制进入当前函数內部的程序
第四个图形示:Step Out,跳出当前函数內部的程式
第五个图形示:Run to Cursor,定位到当前光标