图文讲解nginx+phpstorm+xdebug环境的配置方法

好久没有做php开发,由于近期要维护php项目,在部署开发环境时错误频出,如果可以调试代码,解决问题就非常方便了。于是基于phpstorm+xdebug配置了可以调试的开发环境,期间也查询参考了很多别人的配置过程,发现很多不是很直观或者有遗漏。现在把我的配置步骤记录于此。

1. 安装php+xdebug+nginx

brew install php71 brew install php71-memcached #项目需要,不需要可以不安装 brew install php71-xdebug brew install nginx

2. 配置nginx

vim ~/homebrew/etc/nginx/servers/drone.conf
# 常规配置,可根据自己项目调整server {     listen 80;         # 按自己的需要配置访问的域名     server_name drone-dev.husor.com;     root /data/wwwroot/drone/;          location ~* .php {         fastcgi_pass 127.0.0.1:9000;         include fastcgi_params;         fastcgi_index   index.php;         fastcgi_split_path_info ^(.+.php)(.*)$;         fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;         fastcgi_param   PATH_INFO   $fastcgi_path_info;     } }

3. 配置phpstorm+xdebug

  • 在phpstorm的项目右上角选择Edit Configrations…
图文讲解nginx+phpstorm+xdebug环境的配置方法
  • 新建一个PHP Web Application,如我这里的drone
图文讲解nginx+phpstorm+xdebug环境的配置方法
  • 点击Server后的按钮,新建一个Server,如我这里的nginx
图文讲解nginx+phpstorm+xdebug环境的配置方法
  • 打开phpstorm的Preferences,依次选择Languages & Frameworks > PHP,配置前面安装好的php
图文讲解nginx+phpstorm+xdebug环境的配置方法
图文讲解nginx+phpstorm+xdebug环境的配置方法

点击链接,打开xdebug.ini【相关推荐:phpstorm使用教程

立即学习PHP免费学习笔记(深入)”;

[xdebug] ; 默认zend_extension路径已经配置好了 zend_extension="/Users/xxx/homebrew/opt/php71-xdebug/xdebug.so" xdebug.idekey="macgdbp"xdebug.remote_enable=1 xdebug.profiler_enable=1 xdebug.remote_host="127.0.0.1"xdebug.remote_port=9001 xdebug.remote_handler="dbgp"
图文讲解nginx+phpstorm+xdebug环境的配置方法

Debug port和xdebug.ini中的remote_port一致

4. 启动php+nginx

sudo brew services start nginx brew services start php71# 如果已经启动过的,就重启复制代码

5. 调试代码

  • 点击项目右上角的调试按钮
图文讲解nginx+phpstorm+xdebug环境的配置方法
  • 在断点处停下了
图文讲解nginx+phpstorm+xdebug环境的配置方法

  配置本身不难,我遇到的问题是没有配置Debug port,remote_port配置错误。了解了这两点,基本上可以一次成功。

以上就是图文讲解

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享