圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法

好久沒有做php開發(fā),由于近期要維護(hù)php項(xiàng)目,在部署開發(fā)環(huán)境時(shí)錯(cuò)誤頻出,如果可以調(diào)試代碼,解決問題就非常方便了。于是基于phpstorm+xdebug配置了可以調(diào)試的開發(fā)環(huán)境,期間也查詢參考了很多別人的配置過程,發(fā)現(xiàn)很多不是很直觀或者有遺漏。現(xiàn)在把我的配置步驟記錄于此。

1. 安裝php+xdebug+nginx

brew install php71 brew install php71-memcached #項(xiàng)目需要,不需要可以不安裝 brew install php71-xdebug brew install nginx

2. 配置nginx

vim ~/homebrew/etc/nginx/servers/drone.conf
# 常規(guī)配置,可根據(jù)自己項(xiàng)目調(diào)整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的項(xiàng)目右上角選擇Edit Configrations…
圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法
  • 新建一個(gè)PHP Web Application,如我這里的drone
圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法
  • 點(diǎn)擊Server后的按鈕,新建一個(gè)Server,如我這里的nginx
圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法
  • 打開phpstorm的Preferences,依次選擇Languages & Frameworks > PHP,配置前面安裝好的php
圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法
圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法

點(diǎn)擊鏈接,打開xdebug.ini【相關(guān)推薦:phpstorm使用教程

立即學(xué)習(xí)PHP免費(fèi)學(xué)習(xí)筆記(深入)”;

[xdebug] ; 默認(rèn)zend_extension路徑已經(jīng)配置好了 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環(huán)境的配置方法

Debug port和xdebug.ini中的remote_port一致

4. 啟動(dòng)php+nginx

sudo brew services start nginx brew services start php71# 如果已經(jīng)啟動(dòng)過的,就重啟復(fù)制代碼

5. 調(diào)試代碼

  • 點(diǎn)擊項(xiàng)目右上角的調(diào)試按鈕
圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法
  • 在斷點(diǎn)處停下了
圖文講解nginx+phpstorm+xdebug環(huán)境的配置方法

??配置本身不難,我遇到的問題是沒有配置Debug port,remote_port配置錯(cuò)誤。了解了這兩點(diǎn),基本上可以一次成功。

以上就是圖文講解

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊13 分享