Xdebug With Phpstorm



Postman started out as an API development tool, but has developed more into, as they put it, an 'API Development Environment'.

An over-simplified description is it allows you to create and save requests to test your API. You can then save your requests as a *collection* and share or publish them for others to use.

It supports API calls for all request types, fine control over headers, common authentication methods, and long list of other features that could fill an article... but I wanted to write specifically about using Xdebug with Postman.

Debugging with xdebug and PhpStorm The basic idea in PhpStorm is that you tell it where to look for the xdebug session (the “server”) and then you tell it how to link the files it’s running in the VM to the files found in the repo (called “mapping”). What follows are opinionated defaults, so adjust as. I’ve been developing web applications for about 15 years, but somehow Xdebug is still challenging to set up. Follow along and learn how to find Xdebug settings and configure it for local development with PhpStorm. If you are using PHP-FPM locally, you might have run into an annoying issue that no matter what you do Xdebug won’t work!

How to trigger Xdebug when working with Postman

Recently, I was using Postman to troubleshoot an [API Platform](https://api-platform.com/) project and needed to trigger a Xdebug session in my IDE, [PhpStorm](https://www.jetbrains.com/phpstorm/).

Typically, I rely on a browser extension to trigger Xdebug, however Postman is its own application, so I could not rely on browser extensions.

Fortunately, there's an easy solution: Add `XDEBUG_SESSION_START=PHPSTORM` to the query string and PHPStorm will catch the debug session as it would if you were using a browser extension.

Use Xdebug With Phpstorm

For example, if you are working on `http://localhost:8000/api/users`, simply append the URL with the query string mentioned above to initiate a debug session:

Phpstorm Xdebug Ssh

Now you can set breakpoints and debug as you would if you were working in a browser.

Xdebug Phpstorm Cli

In order to start debugging, you first need to activate the debugger engine on the server. To do this, you need to set a special GET/POST or COOKIE parameter (see the Xdebug and Zend Debugger official documentation for details). While you can do it manually, it is more convenient to use a browser extension, which lets you enable the debugger with a single click.

The following table lists the available debugging extensions.

Php Docker Xdebug Phpstorm

Xdebug phpstorm docker windows

Configure Xdebug Phpstorm

ChromeFirefoxInternet ExplorerSafariOpera
Xdebug

Xdebug Helper or Xdebug-ext

Zend Debugger

zDebug or Zend Debugger Toolbar

Z-Ray for Zend Server version 7 or later. PhpStorm bookmarklets generator otherwise.

  1. Install the Xdebug helper extension for Chrome from the Chrome Web Store.

  2. In PhpStorm, enable listening to incoming debug connections by either clicking on the toolbar or selecting Run | Start Listening for PHP Debug Connections

  3. Initiate connection from the browser side. Click the Xdebug Helper icon on the browser toolbar to initiate a debugging, profiling or tracing session:

  4. As a rule, no further configuration is required. If necessary, you can explore additional settings by right-clicking the Xdebug Helper icon and choosing Options from the context menu.

Xdebug Phpstorm Vagrant

  1. Install Zend Debugger Toolbar.

  2. In PhpStorm, enable listening to incoming debug connections by either clicking on the toolbar or selecting Run | Start Listening for PHP Debug Connections

  3. In the browser, click the Zend Debugger icon on the toolbar and select Settings. Make sure that Autodetect is selected, and the Broadcasting port value matches the value set for Settings broadcasting port on the Debug page in PhpStorm.

  4. Initiate connection from the browser side. Click the Zend Debugger icon on the browser toolbar to initiate a debugging or profiling session: