# Enabling XDebug

## Debugging preparations

### The browser

You need to install [XDebug Helper by JetBrains extension](https://github.com/JetBrains/xdebug-extension) for [Chrome](https://chromewebstore.google.com/detail/xdebug-helper-by-jetbrain/aoelhdemabeimdhedkidlnbkfhnhgnhm) to activate the Debugging session in PHPStorm. Instructions are the same for [Firefox](https://addons.mozilla.org/en-GB/firefox/addon/xdebug-helper-by-jetbrains/).

<figure><img src="https://1705439005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MOVnS5lKxiIvOL9no4d%2Fuploads%2FQqjG48EJKdXTx6n1WE4A%2FScreenshot_20250513_150551.png?alt=media&#x26;token=95ed44c2-aea0-45ac-9854-210795854b5e" alt=""><figcaption><p>Install extension</p></figcaption></figure>

After installation, open extension **options** and select **Debug Trigger** value as **PHPStorm**.

<figure><img src="https://1705439005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MOVnS5lKxiIvOL9no4d%2Fuploads%2Fdqefi7xpo0dp0ypXfGUz%2FScreenshot_20250513_151242.png?alt=media&#x26;token=ee55e256-4476-4156-a4f2-b6d38dd85942" alt=""><figcaption><p>Set Debug Trigger value to PHPSTORM</p></figcaption></figure>

{% hint style="info" %}
This extension sets a cookie in your browser's requests: `XDEBUG_SESSION=PHPSTORM`. This cookie enables debugging in your browser.

Sometimes, you may want to enable debugging outside of the browser (for example, to debug individual GraphQL requests). You can also set `XDEBUG_SESSION=PHPSTORM` manually in the `Cookie` header. Most HTTP and GraphQL clients support this option.
{% endhint %}

Now, when you open your CMA webpage, you need to enable a debug session by pressing **Debug** in the extensions menu.

<figure><img src="https://1705439005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MOVnS5lKxiIvOL9no4d%2Fuploads%2F7wL0Y1I53j5ciOE61Xcs%2Fimage.png?alt=media&#x26;token=3260c032-71c0-470a-8043-3e2202261fef" alt=""><figcaption></figcaption></figure>

### The editor

{% tabs %}
{% tab title="PHPStorm" %}
[Go to settings and activate Docker connection](https://www.jetbrains.com/help/phpstorm/docker.html#install_docker). This needs to be done **once**.
{% endtab %}

{% tab title="VSCode" %}
Install [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug) extension.
{% endtab %}
{% endtabs %}

## Debugging

### First step: Run Create Magento App

Use [start](https://docs.create-magento-app.com/getting-started/available-commands/start) command.

```bash
yarn start # for Yarn
npm run start  # for NPM
```

Wait for the command to finish.

### Second step: Start the debugger

{% tabs %}
{% tab title="PHPStorm" %}
Choose the **create-magento-app** debug configuration in the top right corner of PHPStorm's window.

![](https://1705439005-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MOVnS5lKxiIvOL9no4d%2F-MP5jTo3WmFiCnhFfdjk%2F-MP9paYlLVvTnpiCg1TC%2FScreenshot_20201222_162430.png?alt=media\&token=b7660f74-4b70-4e07-b4ac-860370b2ff19)

Click on **Start debugging** or press **Shift+F9**, put test breakpoint in **$project\_root/pub/index.php** file, reload the page and that is all!

Happy debugging!
{% endtab %}

{% tab title="VSCode" %}
Open debugging tab in VSCode (**Ctrl + Shift + D)** and select **Listen for Xdebug** configuration.

![](https://1705439005-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MOVnS5lKxiIvOL9no4d%2F-MlKvQf6F2140tXw0BX2%2F-MlKyJn6mBiUVuAdbliM%2FScreenshot_20211006_171926.png?alt=media\&token=e02671dc-bbe7-4216-ac91-38149c22a1b0)

Click on **Start debugging** (or press **F5)**, put the test breakpoint in **$project\_root/pub/index.php** file, reload the page and that is all!

Happy debugging!
{% endtab %}
{% endtabs %}
