Enabling XDebug

1. Run Create Magento App in debug mode.

Use start command with debug option to enable XDebug.

yarn start --debug # for Yarn
npm run start -- --debug # for NPM

2. Setup PHPStorm

Set PHP CLI Interpreter

Go to Settings > Languages & Frameworks > PHP Here you need select correct CLI Interpreter for CMA project. CMA is currently using latest PHP 7.4 version so the path to PHP executable should look like this: $HOME/.phpbrew/php/php-7.4.13/bin/php It should look like this:

CLI Interpreters PHP configuration

Set XDebug port and other debugging configuration

Go to Settings > Languages & Frameworks > PHP > Debug Make sure you have set debug port for XDebug to 9003 (which is the default for XDebug 3) and Ignore external connections through the unregistered server configuration is checked.

XDebug settings

Set Debug server configuration

Go to Settings > Languages & Frameworks > PHP > Server There you need to set up a debugging server for Create Magento App. Click +, use http://localhost as Host value, put your Create Magento App running port as Port value, select XDebug as Debugger value.

To find what your Port value is, use status command.

Debug server configuration

Click Apply and close the window.

Set project debug configuration

Go to Run > Edit Configurations Click + and create new PHP Remote Debug configuration. Check Filter debug connection by IDE key, select your create-magento-app debug server as a Server value, use PHPSTORM as an IDE Key value.

Project debug configuration

Click Apply and close the window.

3. Prepare browser

You need to install XDebug Helper extension for Chrome to activate Debugging session in PHPStorm. After installation open extension options and select IDE Key value as PHPStorm.

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

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.

4. Start debugging

Choose create-magento-app debug configuration in the top right corner of PHPStorm's window.

And after that pretty much everything is ready for PHP debugging. 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!