美文网首页
PHP Linux 环境下搭建 XDEBUG并配置远程调试

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

作者: KNKP | 来源:发表于2019-10-30 10:48 被阅读0次

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

    image

    获取下载地址## 下载打包的源码

    
    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

    服务器端安装完成

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

    image image image image image image image

    配置PHPSTORM XDEBUG端口

    image image image image

    配置Xdebug 和 Xdebug 与 PHPSTORM 的通信

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

    image

    进入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 root@110.110.110.128
    
    

    完成。。。。

    XDEBUG 调试示例

    image image image

    个人博客:www.applet.site

    相关文章

      网友评论

          本文标题:PHP Linux 环境下搭建 XDEBUG并配置远程调试

          本文链接:https://www.haomeiwen.com/subject/fncovctx.html