laradock+phpstorm 開啟 xdebug

stonelalala發表於2019-11-18

最近在學L05的電商教程,前面基本都不需要debug,看到支付寶回撥這邊,遇到點問題,想看一下回撥中返回的串解析出來的資料。之前一直沒配置debugg,記錄一下怎麼開啟。

  1. 編輯laradock的.env檔案
    查詢:WORKSPACE_INSTALL_XDEBUG
    將原本的值false改為true
    查詢:PHP_FPM_INSTALL_XDEBUG
    將原本的值false改為true

  2. 編輯workspace和php-fpm的xdebug.ini檔案
    這邊直接貼一下我的配置
    workspace的xdebug.ini

    xdebug.remote_host=host.docker.internal
    xdebug.remote_connect_back=0
    xdebug.remote_port=9000
    xdebug.idekey=PHPSTORM
    xdebug.remote_autostart=0
    xdebug.remote_enable=1
    xdebug.cli_color=0
    xdebug.profiler_enable=0
    xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.var_display_max_children=-1
    xdebug.var_display_max_data=-1
    xdebug.var_display_max_depth=-1

    php-fpm的xdebug.ini

    xdebug.remote_host=host.docker.internal
    xdebug.remote_connect_back=0
    xdebug.remote_port=9000
    xdebug.idekey=PHPSTORM
    xdebug.remote_autostart=0
    xdebug.remote_enable=1
    xdebug.cli_color=0
    xdebug.profiler_enable=0
    xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.var_display_max_children=-1
    xdebug.var_display_max_data=-1
    xdebug.var_display_max_depth=-1
  3. 重新laradock的workspace和php-fpm的映象
    docker-compose build workspace php-fpm
    build完之後需要重啟laradock。
    4.配置PHPSTORM
    新增server
    laradock+phpstorm開啟xdebug
    配置DBGp Proxy
    laradock+phpstorm開啟xdebug
    點選debug頁籤中的validate,配置一下你的專案,然後按視窗右下角的validate,如圖為驗證通過的介面,如果驗證不通過的話,會有相應的提示。這個validata也可以在配置監聽那邊驗證。
    laradock+phpstorm開啟xdebug
    點選phpstorm右上角的的圖中的這個選項,進入配置頁面
    laradock+phpstorm開啟xdebug
    laradock+phpstorm開啟xdebug
    新增完之後點選確定。

  4. 檢視除錯效果
    用curl方式進行請求
    laradock+phpstorm開啟xdebug
    除錯介面
    laradock+phpstorm開啟xdebug

  5. 關於開啟與關閉xdebug
    在laradock的根目錄可以進行xdebug的開關
    命令分別為:
    開啟php-fpm/xdebug start

laradock+phpstorm開啟xdebug

關閉php-fpm/xdebug stop

laradock+phpstorm開啟xdebug
建議需要使用debug的時候才開啟,因為開啟debug,請求的時間相差很大。
同一介面,開啟debug與不開啟請求時間的差別。
開啟:
laradock+phpstorm開啟xdebug
關閉:
laradock+phpstorm開啟xdebug

相關文章