在網站 [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)