论持久战之PHPStorm Xdebug Remote 调试环境

最近公司自己搭建了一个资源管理平台,哈哈,当然是我在github上找的,后台用PHP开发。个人觉得写得非常nice,web页面几乎模拟了真实OS,有兴趣的朋友下载部署体验https://github.com/kalcaddle/KODExplorer
作为一个Java程序猿来说本地只有Java环境,服务器上搭建了Nginx+PHP7环境,有朋友会提出质疑难道不需要数据库吗?服务器上肯定有MySQL数据库,但这个资源管理平台真的不需要数据库。部署完成开始体验测试,刚登录浏览器就报过多的重定向问题;完蛋准备调试代码吧。本地没有PHP环境怎么办?我个人比较懒,当时想到了PHP既然是动态语言,那我是不是就不用配置本地环境直接远程调试了呢?度娘肯定了我的想法,那就开干吧!
首先在服务器上下载xdebug包,解压用phpize编译安装扩展,关于编译安装就不做过多介绍了;扩展安装完成后配置php.ini文件

下面介绍几个主要配置项:
#允许远程调试
xdebug.remote_enable=1
#如果配置该项就不需要配xdebug.remote_host
xdebug.remote_connect_back=1
#远程调试端口
xdebug.remote_port=9001
#调试器的关键字
xdebug.idekey="PHPSTORM"
配置完成后重启php-fpm 记得加-R 使用root用户启动
进入PHPStorm配置(完全远程调试)
为什么说完全远程调试呢?
1.不依赖本地PHP环境
2.不依赖本地webserver
3.浏览器不需要装调试插件
我的phpstorm版本是2016.2,其他版本是否需要依赖前三项未知。
完全依赖服务器PHP环境
第一步配置远程项目路径与本地项目路径映射
①连接服务器

②添加映射

第二步phpstorm配置远程PHP环境


到此已经完成一半了,接下来开始配置phpstorm的xdebug端口

继续配置远程server

开始运行测试



OK配置全部完成
还有最最关键的一步,配置路由器端口映射
发起了远程调试请求,但是IDE需要接收调试信息,大部分开发人员都是在局域网内开发,需要将xdebug返回9001端口映射到本机9001端口;关于这一步不同的路由器配置方式不同,提供一个搜索关键词“路由器配置虚拟服务器”或寻求公司运维人员帮助
演示效果

以上属于原创文章,转载请注明作者@怪咖
QQ交流群:830425441