Using Xdebug & PhpStorm

Once you’ve created a machine, you can run nitro xdebug on to enable Xdebug and set it up for automatic connections from your host machine.

You can use nitro xdebug off to disable Xdebug without having to restart the machine.

# Configuring PhpStorm

First, you’ll need to configure PhpStorm to listen for requests from the browser or console.

  1. Create a new server in PhpStorm using your machine’s domain name. (“Preferences” → “Languages & Frameworks” → “PHP” → “Servers”.)
    PhpStorm Server Settings

  2. Enable “Use path mappings” and set your existing project root to the absolute path on the server. The absolute path will look like /home/ubuntu/sites/my-site, where my-site reflects your actual project’s folder name in the Nitro machine. (Use nitro context if you need to check the path, and keep in mind this is the project root and not necessarily the web root.)

  3. Choose “Run” → “Edit Configurations...” and create a new “PHP Remote Debug” configuration, selecting the server you just created. Check “Filter debug connection by IDE key” and enter PHPSTORM.
    PhpStorm Remote Debug Settings

  4. Choose “Run” → “Start Listening for PHP Debug Connections”.
    PhpStorm Remote Debug Settings

# Debugging Web Requests

  1. Install the Xdebug helper in your favorite browser.
  1. In the browser helper’s options, choose “PhpStorm” and save.
    Xdebug Browser Helper Chrome

  2. Choose “Debug” on your browser’s Xdebug helper.
    PhpStorm Remote Debug Settings

  3. Load the site in your browser and whatever breakpoints you’ve set will be hit.

# Debugging Console Requests

SSH into your Nitro machine using nitro ssh, then run your PHP script from the console and any breakpoints you’ve set will be hit.