0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel9 sail vscodeでデバッグする

Posted at

# はじめに
LaravelとXdebugのバージョンが上がり、手順が変更になったので、整理しました。
以前の手順は以下を参照ください。

検証環境

  • Laravel Framework 9.1.0
  • Windows 10 Pro
  • Visual Studio Code
  • Docker Desktop for Windows
  • PHP v8.1.2
  • Xdebug v3.1.2

Xdebugを設定する

.envファイルに以下の設定を追加します。

.env
% SAIL_XDEBUG_MODE=develop,debug

Sail起動

PowerShell
% ./vendor/bin/sail up -d

Xdebugが導入されていることを確認

PowerShell
./vendor/bin/sail php -v
PHP 8.0.5 (cli) (built: May  3 2021 11:30:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.5, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

larave.testコンテナのPHPバージョンを確認することで、Xdebugがインストールされているか確認できます。
Xdebugが表示されていれば、問題なくインストールが完了しています。

VSCodeに構成ファイルを追加する

{
    // IntelliSense を使用して利用可能な属性を学べます。
    // 既存の属性の説明をホバーして表示します。
    // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceRoot}"}
        },
        
    ]
}

VSCodeよりブレークポイントを設定

image.png

VSCodeよりデバッグを開始

image.png

ブラウザよりアクセス

URLに以下を追加してアクセスする。
?XDEBUG_SESSION_START=session_name
最初のURLに指定すれば、デバッグを停止するまでは、指定は必要ありません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?