好久没有做php开发,由于近期要维护php项目,在部署开发环境时错误频出,如果可以调试代码,解决问题就非常方便了。于是基于phpstorm+xdebug配置了可以调试的开发环境,期间也查询参考了很多别人的配置过程,发现很多不是很直观或者有遗漏。现在把我的配置步骤记录于此。
1. 安装php+xdebug+nginx
brew install php71brew install php71-memcached #项目需要,不需要可以不安装brew install php71-xdebugbrew 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...
新建一个php web application,如我这里的drone点击server后的按钮,新建一个server,如我这里的nginx打开phpstorm的preferences,依次选择languages & frameworks > php,配置前面安装好的php点击链接,打开xdebug.ini【相关推荐:phpstorm使用教程】
[xdebug]; 默认zend_extension路径已经配置好了zend_extension=/users/xxx/homebrew/opt/php71-xdebug/xdebug.so xdebug.idekey=macgdbpxdebug.remote_enable=1xdebug.profiler_enable=1xdebug.remote_host=127.0.0.1xdebug.remote_port=9001xdebug.remote_handler=dbgp
debug port和xdebug.ini中的remote_port一致
4. 启动php+nginx
sudo brew services start nginxbrew services start php71# 如果已经启动过的,就重启复制代码
5. 调试代码
点击项目右上角的调试按钮在断点处停下了 配置本身不难,我遇到的问题是没有配置debug port,remote_port配置错误。了解了这两点,基本上可以一次成功。
以上就是图文讲解nginx+phpstorm+xdebug环境的配置方法的详细内容。