laradock phpstorm xdebug

安裝 Xdebug 擴展

  • 編輯 laradock 目錄下 .env 文件,修改如下兩項
    WORKSPACE_INSTALL_XDEBUG=true PHP_FPM_INSTALL_XDEBUG=true
  • 修改後執行 docker-compose build php-fpm workspace 使配置生效
 

配置 Xdebug

    • 編輯 laradock/workspace/xdebug.ini 及 laradock/php-fpm/xdebug.ini,具體配置以下php

      xdebug.remote_host=docker.for.win.localhost xdebug.remote_connect_back=0 xdebug.remote_port=9000 xdebug.idekey=PHPSTORM xdebug.remote_autostart=0 xdebug.remote_enable=0 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

      其中 remote_host 很關鍵。我使用的是 windown,如使用 Mac 應修改成 docker.for.mac.localhost(ps:能夠在未配置成功的狀況下,運行西面的vildate 根據他的提示,填寫remote_host)laravel

       
       

      配置 PhpStorm

    • 配置 PHP server,具體配置如圖docker

      file
       

      其中 server name 需和 laradock 目錄中 .env 文件中 PHP_IDE_CONFIG 配置項一致,默認爲 laradock

       

    • 配置、驗證 Xdebug瀏覽器

      • 配置保持默認配置便可,修改完配置後需校驗配置
        file
         
      • 點擊 Validate 後界面如圖
        file
         

        點擊下方 Validate 按鈕,校驗成功後如圖
        file
         

        填寫校驗腳本地址時,需注意,如項目爲 laravel ,目錄必須爲 public 目錄。在這一步我被坑了好久,直接填寫項目目錄校驗會 404
      • 添加 debug 項目配置
        run -> Edit Configurations,添加 PHP Remote Debug。其中 server 爲 laradock 的 PHP_IDE_CONFIG 配置項,默認爲 laradock,IDE key 爲 PhpStorm。如圖:
        file
         
      • 配置完成後,選擇上一步配置的 remote debug 啓功,設置斷點,刷新瀏覽器項目網頁,便可開始調試。
      • 注意:xdebug.ini是由laradock/php-fpm文件下的xdebug.int複製進去的,因此若是要修改要麼重新build php-fpm或者進入php-fpm容器進行修改xdebug.ini配置,配置文件地址「/usr/local/etc/php/conf.d/」
      • 運行phpstorm可能出現文件映射錯誤的提示,這時候須要在setting/languages&framework/PHP/Servers新增的laradock進行編輯,使用use path mapping,幷把project files裏面的Aboslute path on the server改成laradock文件目錄地址
相關文章
相關標籤/搜索