Xdebug With Postman



  1. Xdebug With Postman Download
  2. Xdebug Postman Vscode

Debugging with Postman and PHPStorm (Xdebug) Written by Mike August 6, 2018 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. While filling the details, make sure the setting specified in the php.ini file should match with IDE KEY and click Ok. Open the PHP file you want to debug in the Notepad and add a breakpoint to the script. You will see the Notepad icon blinking on the taskbar. Click on it and start debugging. To make Xdebug work with VS Code, we need to install the PHP Debug extension by Felix Becker. Since we already installed Xdebug and configured the required.ini settings above, there is no further configuration needed at this point. Once this is done, we are ready to start our first debugging session. Debugging our first Kirby controller. I updated the xdebug.so file (Linux) and php -version indicated that xdebug was indeed being loaded and working. But when I would use Postman the debugger never kicked on. But when I would use Postman the debugger never kicked on. Xdebug's step debugger allows you to interactively walk through your code to debug control flow and examine data structures. Xdebug interacts with IDEs to provide step debugging functionality, and therefore you also need to configure an IDE that knows how to talk to Xdebug with the open DBGp protocol.

Xdebug With Postman Download

August 11, 2016Yann Jacquot6 min read

Warning: this article concerns php5 version. If your PHP version is different, replace php5 by php/X.Y in paths (X.Y is your PHP version) and phpX.Y in command. For example :

  • sudo apt-get install php5-xdebug becomes sudo apt-get install php5.6-xdebug
  • /etc/php5/mods-available/xdebug.ini becomes /etc/php/5.6/mods-available/xdebug.ini

I love debuggers. They allow me to understand deep down in my code why something doesn't work, and are even more useful when I work on legacy projects.
When I work on the client side, the browser already provides me all the tools I need to dig deeper than some console.log() scattered semi-randomly in the source code.
However, I struggled to configure my workspace when I worked on a PHP Symfony2 project hosted in a Vagrant virtual machine.

Step1: Install Xdebug on your Vagrant virtual machine

That may seem obvious, but you need to have Xdebug installed on your virtual machine to benefit from its services.

Xdebug Postman Vscode

Then, configure it:

with the following lines:

Finally, if you use php5-fpm, you need to restart it:

If you use Ansible to provision your virtual machine, you can also use a ready-to-action Xdebug role.

Step2: Configure PhpStorm

Xdebug

First, select the 'Edit configurations' item in the 'Run' menu.

Then, add a new 'PHP Remote Debug' configuration.

We will use the IDE key configured in your Vagrant and in your browser.
To fully configure this debugger configuration, you will need to create what PhpStorm calls a server.

  • Fill the correct hostname
  • Check 'Use path mappings' checkbox, and write the project's absolute path
    on your Vagrant virtual machine

Step3: Configure Xdebug

Use Xdebug to debug your web application on Chrome

Now that Vagrant with Xdebug is up and running, let's configure Xdebug Chrome extension.

First, we need to install it from Chrome Web Store

Make sure that the extension is enabled on your browser's extensions list page.

Now, you should see on the right side of the address bar the extension's symbol.

Right-click on it, then click on the 'Options' sub-menu.

You have to use the IDE key previously set.

Xdebug plugin also exists for other browsers.

Finally, in your browser click on the bug in your address bar to switch to the 'Debug' mode

Use Xdebug to debug your APIs route with Postman

Once your Xdebug configuration is added, you need to add ?XDEBUG_SESSION_START=_<XDEBUG_KEYNAME>_ at the end of your route. And that's all!

Use Xdebug to debug commands or unit tests

To use Xdebug for debugging commands or unit tests, first, you need to add xdebug.remote_autostart=true in XDebug configuration file of your Vagrant xdebug.ini.

Then, you need to specify the xdebug.remote_host (IP address of your local from your Vagrant) when launching the command from the virtual machine’s terminal.

  • First, get the host IP address by using ifconfig from your local terminal (the host) :
  • Then, launch your command

For instance, if you want to debug your unit tests in a Symfony project, you can run:

Step4: Enjoy!

Now, in PhpStorm you:

  • Add your breakpoints by clicking to the left of the lines
  • Click on the bug icon on the upper-right corner

You should now be able to break on the exact line you selected in your IDE.

Bonus: Performance

You need to know that enabling Xdebug slows down your app (x2), the fastest way to disable it is to run the following command: php5dismod xdebug

Use php5enmod xdebug to enable it back. Each time you'll also need to restart php-fpm or apache.

Troubleshooting: I did the tutorial but Xdebug doesn’t work

It’s probably because a symbolic link is missing in your php conf.

  • First type in your virtual machine php -i | grep xdebug

If you have no response, it means Xdebug is not set correctly

  • Then check if Xdebug is mentioned when running php -v from your Vagrant.
  • If not, add a symbolic link to specify that the Xdebug module should be enabled, for instance (you may need sudo):
  • You should obtain by running php -v

I hope you've made your way through the process and that it will improve your efficiency as much as it does for me. If you have other ways to configure your debugger, feel free to share them in the comments section below.

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

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.

Xdebug

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.

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. App store macos sierra.

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.