LoginSignup
0
1

PHPインストール(8.1)とxdebugの設定(vscode)

Last updated at Posted at 2023-05-30

本記事は以下の環境で動作確認しています。

OS: macOS Venture 13.3.1
Chip: Apple M1 Pro

前提として、homebrew は導入済み。

PHP8.1のインストール

インストールコマンドは、以下。

brew install php@8.1

確認。

which php

/opt/homebrew/opt/php@8.1/bin/php

xdebugの導入

以下記事が参考になります。

php.ini ファイルの確認。

vim /opt/homebrew/etc/php/8.1/php.ini

zend_extension="xdebug.so"

launch.jsonを定義してデバッグ実行

vscodeのプロジェクトディレクトリでlaunch.jsonを定義。
Screenshot 2023-05-30 at 11.00.44.png

launch.json

"configurations": [
    {
      "name": "Listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9003
    },
]

ブレイクポイントを設定し、F5キーでデバッグ開始も動作していない模様。
ちなみにブレイクポイントは、vscode extensionでPHP debugを導入していないと設定できません。

既存プロジェクトで確認

こちらで作成したsymfonyプロジェクトを使用。

任意のコントローラを作成。: src/Controller/InfoController.php
phpinfo()を埋め込みます。

namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class InfoController extends AbstractController
{
    /**
     * @Route("/info", name="get_info")
     */
    public function getInfo(): Response
    {
        phpinfo(); // 情報確認。
        return new Response();
    }
}

https://127.0.0.1:8000/info

⌘ + fxdebugを検索。

Xdebug
Version 3.2.1
Step Debugger Disabled docs
xdebug.client_port 9003

step debuggerの設定値がdisabledなので必要な設定をドキュメントを参照して確認します。

php.iniを修正

必要な設定が確認できたら、php.iniファイルを修正します。

xdebug.mode=debug
xdebug.start_with_request=yes

動作確認

プロジェクトを再起動して動作確認します。

symfony server:start

Screenshot 2023-05-30 at 11.15.39.png

0
1
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
1