PHP Linux 环境下搭建 XDEBUG并配置远程调试

在网站 [https://xdebug.org/download.php](https://xdebug.org/download.php) 找到对应PHP版本的XDEBUG下载,下载时选择source版本

![image](https://upload-images.jianshu.io/upload_images/10757675-2855eba9500ead88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)获取下载地址## 下载打包的源码

```

wget https://xdebug.org/files/xdebug-2.5.5.tgz

```

## 解包

```

 tar zxvf xdebug-2.5.5.tgz

```

## 进入解包后的源码目录

```

cd xdebug-2.5.5

```

## 执行 phpize 生成配置文件脚本 configure

```

phpize

```

## 查找php-config 的位置

```

find / -name php-config

```

## 执行 configure 脚本 --with-php-config=php-config的路径

```

 ./configure --with-php-config=/usr/local/php/bin/php-config

```

## 编译源码

```

make

```

## 编译生成PHP的扩展模块,成功完成后根据提示( Installing shared extensions: )找到模块路径记录下来后面要用来配置xdebug

```

make install

```

![image](https://upload-images.jianshu.io/upload_images/10757675-da1b2743f0554bce.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)服务器端安装完成

配置PHPSTORM 连接上服务器,相当于 ftp

![image](https://upload-images.jianshu.io/upload_images/10757675-7c3930e1e71509d1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-cf2bc5a39d844c8d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-50b0b89e428d35d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-3880aa36a9a116bf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-ae34ac125a6943c3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-1d7ff575758274d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-67c50749292bc1e6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)配置PHPSTORM XDEBUG端口

![image](https://upload-images.jianshu.io/upload_images/10757675-44947c64c28b56ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-4c7b8a9994cfba05.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-c5680ee4f0a5353a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-a897108ce98df3c1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)配置Xdebug 和 Xdebug 与 PHPSTORM 的通信

查看PHP载入的所有配置文件

![image](https://upload-images.jianshu.io/upload_images/10757675-7fad27263a1b6c6a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)进入PHP会扫描的配置文件夹,添加xdebug的配置,这里要注意可能只是命令行的配置文件,不代表 php-fpm 也会使用这些配置,如果后面没有在 phpinfo 中看到xdebug, 先重启 php-fpm 和 nginx,如果还是无效那么要去 php-fpm 读取的配置中设置 xdebug 的配置

```

; so 的路径 make install 成功后有提示,上面讲过

zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so

xdebug.remote_enable=1

;远程IP(公网IP),由于公网IP是动态的,

;但是没有路由器权限,又不能做端口映射

;所以这里采用 SSH 隧道的方式转发

xdebug.remote_host=127.0.0.1

;远程调试端口

xdebug.remote_port=9020

;调试器的关键字

xdebug.idekey=PHPSTORM

xdebug.remote_handler=dbgp

xdebug.remote_mode=req

xdebug.remote_log=/var/log/php/xdebug.log

xdebug.remote_timeout=20000

```

## 重启 php-fpm 和 nginx

```

systemctl restart php-fpm

systemctl restart nginx

```

建立后台运行的SSH隧道

```

ssh -f -N -R 192.168.1.197:9020:127.0.0.1:9020 [email protected]

```

完成。。。。

XDEBUG 调试示例

![image](https://upload-images.jianshu.io/upload_images/10757675-cbb7a5818ef3b11d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-e779ed7bb111554e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![image](https://upload-images.jianshu.io/upload_images/10757675-59e34147376d518d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


个人博客:[www.applet.site](www.applet.site)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章