圖文講解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 分享