Phpstorm Xdebug Postman

  



  1. Configure Xdebug Phpstorm
  2. Phpstorm Xdebug Postman Extension
  3. Phpstorm Xdebug Postman Tutorial
  4. Phpstorm Xdebug Ssh

This blog post shows how to setup a fully dockerized development suite with PhpStorm, GIT and Postman. But what is development without debugging? If all apps are dockerized you will need a workaround to be able to debug the application e.g. with PhpStorm and Xdebug. This is also considered. If you not familiar with Dockerized desktop apps, check out the Dockerized introduction. You should create your own Docker images, but for testing my Docker images should work too. The bash scripts refer to a folder data/x11docker in your home directory where x11docker stores the container config. Please create it before.

PhpStorm supports debugging with the two most popular tools: Xdebug and Zend Debugger. These tools can not be used at the same time because they block each other. To avoid this problem, you must update the appropriate sections of the php.ini file, as described in Configuring Xdebug.

Setup GIT

  • Use XDebug on a Devilbox with PhpStorm and Postman Host OS. Tested on: openSUSE 15.1 Leap; Fedora 30; Ubuntu 18.04.3 LTS; Pop!OS 19.10 (might apply to most recent Ubuntu derivates).
  • Xdebug and Postman. If you wish to debug a request sent by Postman, all you need to do is add XDEBUGSESSIONSTART=PHPSTORM as a key-value pair to the request body and start the debug config as you would when debugging via Chrome. Developer documentation - Previous.

To work properly with Dockerized GIT you need three things. A Docker container with GIT, the mounted source of course and your SSH credentials.

Docker Image

Let's start with the GIT Docker image. The minimal packages are git and openssh.

Start script

One cool thing of x11docker is, that it does all the heavy lifting. Don't worry about file permissions, how to share the ssh socket or to mount directories. All my sources are stored under data/sources. This makes it easy to mount the root source directory. I set the working directory to the current directory where the git command is executed. With this is feels like native GIT usage.

Create the following script named git and put it to a directory which is in your PATH variable e.g. ~/bin and make it executable.

Now you can use GIT as always and it works seamlessly. Ok, there are some small caveats. The start time is compared to native GIT long and you don't have bash completion. But I use PhpStorm mostly for VCS stuff.

If some SSH keys are not found, you can mount the ssh folder with --sharedir $HOME/.ssh:ro.

Setup PhpStorm

To work efficiently with Dockerized PhpStorm you will need a Docker container with PhpStorm and the same packages like in the GIT dockerfile.

Phpstorm Xdebug Postman

Docker Image

PhpStorm can be downloaded and extracted to /opt. I use this method in my PhpStorm Docker image. You will need the packages git, openssh, vim, gnome-keyring and libsecret to work properly. PhpStorm stores connection credentials in the Linux keyring.

Start script

The PhpStorm script has some more options like git, because we need a clipboard for copy & paste and hostdbus for credentials. I use also hostdisplay but you can also try xpra. To debug applications with PhpStorm you must add PhpStorm to the network of the application which should be debugged. I use a trick in the PhpStorm startup script to add the phpstorm container to every default network.

You have to set the xDebug XDEBUG_CONFIG option to remote_host=phpstorm and ensure that xdebug.remote_connect_back is disabled. Read more about Docker PHP debugging.

Setup Postman

Postman is a popular tool for API development. It has many features like test, debug and documentation of your APIs.

Docker Image

Simply install Postman for your distro. That's it.

Start script

To interact with other Docker containers via a local domain you have to add the add-host option with the IP of your Docker network. In this example it's 172.17.0.1 but may be vary on your host. You can also share your Downloads folder to import / export Postman collections. Debugging your APIs with xDebug works like a charm.

Chromium

I use a dedicated Chromium for development with installed development plugins. Some plugins have access to all data of the webpage or can even manipulate the website data. To browse a development website which is served by a Docker container via a local domain you have to add the add-host option with the IP of your Docker network.

Conclusion

This blog post has shown how to setup a complete development environment with Docker. It's not very complicated but you have to figure out a few things. It's almost a native feeling and has so many benefits, such as: Run different versions of same application. The best thing is, that you not bloat your host system with other software.

03 Dec 2020

Configure Xdebug Phpstorm

Requirements

  • XAMPP for Windows: https://www.apachefriends.org/download.html

Setup

  • Download Xdebug for the specific PHP version:
    • PHP 8.0 (64-Bit): https://xdebug.org/files/php_xdebug-3.0.0-8.0-vs16-x86_64.dll
  • Move the downloaded dll file to: C:xamppphpext
  • Rename the dll file to: php_xdebug.dll
  • Open the file C:xamppphpphp.ini with Notepad++
  • Disable output buffering: output_buffering = Off
  • Scroll down to the [XDebug] section (or create it) and copy/paste these lines:
  • Restart Apache

PhpStorm

  • Enable the Xdebug option: “Can accept external connections” and “Additionally listen on Xdebug 3 default port 9003”. Screenshot
  • Use the PhpStorm bookmarklets generator to activate Xdebug from the browser side.

Netbeans

  • Change the Netbeans debugging options: Screenshot

Visual Studio Code

  • Install the PHP Debug Adapter for Visual Studio Code.

Postman

Add XDEBUG_SESSION_START=PHPSTORM as query parameter to the url, e.g.

  • http://localhost?XDEBUG_SESSION_START=PHPSTORM

Start debugger from the console

Phpstorm Xdebug Postman Extension

Enter cmd:

Phpstorm Xdebug Postman Tutorial

Known Issues

Phpstorm Xdebug Ssh

Please enable JavaScript to view the comments powered by Disqus.