Homestead+PhpStorm+Xdebug 遠端除錯

Lance發表於2020-04-03

配置Homestead

  1. 通過ssh登入到虛擬機器中
  2. 通過命令找到閘道器(用於配置後續的remote_host)
    netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
  3. 編輯xdebug的配置檔案
    sudo vim /etc/php/7.2/fpm/conf.d/20-xdebug.ini
    zend_extension=xdebug.so
    xdebug.remote_enable = 1
    xdebug.remote_port=9000 # 遠端通訊埠
    xdebug.max_nesting_level=512
    xdebug.remote_host=10.0.2.2 # 上文中提到的閘道器地址
    xdebug.remote_autostart=1 # 自動啟動設為true
  4. 重啟nginx和php
    sudo service php7.2-fpm restart
    sudo service nginx restart

配置phpstorm

  1. 開啟設定,依次選擇Languages & Frameworks => PHP ,進行對應的設定 密碼為vagrant

Homestead+PhpStorm+Xdebug遠端除錯

  1. 配置路徑對映

Homestead+PhpStorm+Xdebug遠端除錯

  1. Xebug,一般預設設定就行

Homestead+PhpStorm+Xdebug遠端除錯

  1. 點選Validate進行驗證,將本地的public目錄和遠端的訪問url填寫後,點選Validate,對應有不對的依照提示更改

Homestead+PhpStorm+Xdebug遠端除錯

  1. 配置Servers,host填寫app的地址,注意進行map對映本地和遠端目錄

Homestead+PhpStorm+Xdebug遠端除錯

  1. 點選Run=>Edit Configrations,新增一個PHP Remote Debug

Homestead+PhpStorm+Xdebug遠端除錯

  1. 至此,phpstorm配置完成,點選圖示開始監聽,然後點選綠色小蟲開始debug

Homestead+PhpStorm+Xdebug遠端除錯

使用瀏覽器開啟網頁進行除錯

http://shop.test/?XDEBUG_SESSION_START=PHP...
Homestead+PhpStorm+Xdebug遠端除錯

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章