Skip to content

Instantly share code, notes, and snippets.

@Im0rtality
Last active March 17, 2023 14:36
Show Gist options
  • Save Im0rtality/9710254 to your computer and use it in GitHub Desktop.
Save Im0rtality/9710254 to your computer and use it in GitHub Desktop.
PHP CLI Debugging in Vagrant using Xdebug and PHPStorm

In guest:

  1. Create file /usr/bin/debug with contents added below (file debug below)
  2. Make it executable $ sudo chmod 0777 /usr/bin/debug

In host:

  1. Go to PHPStorm Settings > Project settings > PHP > Servers
  2. Add server with following parameters:
    • Name: vagrant (same as serverName= in debug script)
    • Host, port: set vagrant box IP and port
    • Debugger: Xdebug
    • [v] Use path mappings
    • Map your project root in host to relative dir in guest
    • Hit OK
#!/bin/sh
env PHP_IDE_CONFIG="serverName=vagrant" XDEBUG_CONFIG="idekey=PHPSTORM" SYMFONY_DEBUG="1" $@
@pavarnos
Copy link

pavarnos commented Aug 8, 2019

you can also

  • in phpStorm Settings > Run > Edit Configurations
  • add a PHP Script configuration
  • set the file to the full local filesystem path eg /your/path/to/app/console
  • set arguments eg cache:clear
  • set environment variables to PHP_IDE_CONFIG="serverName=vagrant";XDEBUG_CONFIG="idekey=PHPSTORM"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment