Skip to content

Instantly share code, notes, and snippets.

@alfredbez
Forked from Im0rtality/README.md
Last active November 23, 2016 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredbez/a7e44dc6a7a17eea87c799acc357d9ea to your computer and use it in GitHub Desktop.
Save alfredbez/a7e44dc6a7a17eea87c799acc357d9ea to your computer and use it in GitHub Desktop.
PHP CLI Debugging in Vagrant using Xdebug and PHPStorm

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
  3. PHPStorm > Run > Start listen for PHP Debug connections
  4. Put a breakpoint

In guest:

  1. Find where your Xdebug config is stored. Run $ php -i | grep ini and look for *xdebug.ini or *custom.ini - depends on configuration (mine was in /etc/php5/cli/conf.d/zzzz_custom.ini)
  2. Add following xdebug.remote_host = 11.22.33.1, when box ip is 11.22.33.*
  3. Create file /usr/bin/debug with contents added below (file debug below)
  4. Make it executable $ sudo chmod +x /usr/bin/debug
  5. Run your script prefixed with debug:
    • $ debug app/console cache:clear    - or $ debug php /path/to/script.php
  6. Debugger window should open in IDE
#!/bin/sh
env PHP_IDE_CONFIG="serverName=vagrant" XDEBUG_CONFIG="idekey=PHPSTORM" $@
# for Symfony apps use following
# env PHP_IDE_CONFIG="serverName=vagrant" XDEBUG_CONFIG="idekey=PHPSTORM" SYMFONY_DEBUG="1" $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment