Xdebug Postman



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.

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). Post (he/him/his)’s profile on LinkedIn, the world’s largest professional community. Has 8 jobs listed on their profile. See the complete profile on LinkedIn.

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.

Xdebug Postman Download

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

Xdebug Postman

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

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.

Postman

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

Xdebug Postman

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.

Xdebug Docker Phpstorm Postman

Before you start debugging, make sure that you have a debugging engine installed and configured properly. PhpStorm supports debugging with two most popular tools: Xdebug and Zend Debugger. These tools cannot be used simultaneously because they block each other. To avoid this problem, you need to update the corresponding sections in the php.ini file as described in Configure Xdebug and Configure Zend Debugger.

With PhpStorm, a PHP debugging session can be initiated either through a run/debug configuration or without it. The latter approach is also called Zero-configuration debugging. PhpStorm supports three main ways to initiate a PHP debugging session:

  • You create a PHP Web Page debug configuration, and then PhpStorm uses its settings to launch the application, open the browser, and activate the debugging engine.

  • You create a PHP HTTP Request debug configuration or an HTTP request in the code editor, PhpStorm generates a request on its base, and then accesses a specific page through this request.

  • Zero-configuration debugging, when no debug configuration is created at all. Instead, you open the starting page of your PHP application in the browser manually and then activate the debugging engine from the browser, while PhpStorm listens to incoming debugger connections.

No matter which method you choose, you can specify the scripts requests to which you want PhpStorm to ignore during debugging. This approach can be useful, when your application contains scripts that use AJAX. Suppose you have a menu-ajax-script.php that 'reloads' a part of your web page. This script works properly so you do not need to debug it. However, this script is still requested during the debugging session. To have incoming connections to this script ignored, add the menu-ajax-script.php script to the skipped paths list.

If a script is added to Skipped paths, it is only skipped when starting a debugging session for it. To ignore a script when stepping through the program during a debugging session, configure a stepping filter.

Postman

When using Xdebug, you can also debug PHP applications in the multiuser mode via Xdebug proxy servers.

Pause a debugging session

Xdebug Debug Postman

  • From the main menu, choose Run | Debugging Actions | Pause Program.

  • Click on the Debug toolbar.

    This action is not available for Run/Debug Configuration: Attach to Node.js/Chrome.

Resume a debugging session

  • From the main menu, select Run | Debugging Actions | Resume Program.

  • Click in the Debug tool window or press F9.

Restart a debugger session

  • Click in the Debug tool window or press Ctrl+F5.

Terminate a debugger session

Xdebug debug postman
  • Click the in the Debug tool window. Alternatively, press Ctrl+F2 and select the process to terminate (if there are two or more of them).