Skip to content

Instantly share code, notes, and snippets.

@thejettdurham
Last active November 1, 2021 23:43
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save thejettdurham/bd2a80d292bebe4a3c3bc0f34acc2d47 to your computer and use it in GitHub Desktop.
Save thejettdurham/bd2a80d292bebe4a3c3bc0f34acc2d47 to your computer and use it in GitHub Desktop.
Debugging laravel/lumen + artisan from Homestead with PHPStorm over xdebug

This config works for me with the following setup, YMMV

  • OSX El Capitain
  • PHPStorm 2016.2.1
  • Lumen 5.2
  • Homestead as of Lumen 5.2
    • php 7.0.8-2
    • Xdebug 2.4.0

Homestead Configuration

  • Ensure xdebug module is enabled in CLI and FPM: sudo phpenmod -s cli xdebug sudo phpenmod -s fpm xdebug
  • Add xdebug config to /etc/php/7.0/fpm/php.ini and restart service
[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey=PHPSTORM
xdebug.remote_host=yourhostname.app
  • Add xdebug config to /etc/php/7.0/cli/php.ini
[xdebug]
xdebug.remote_enable=1
xdebug.remote_log="/home/vagrant/xdebug.log"
xdebug.remote_handler=dbgp
xdebug.collect_params=1
xdebug.remote_connect_back=0
;use `route -n` to find dev machine IP address from homestead environment (seems to default to 10.0.2.2)
xdebug.remote_host="10.0.2.2"
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.show_local_vars=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir='/home/vagrant/profile'
xdebug.idekey=PHPSTORM
  • Add environment variables and command aliases to ~/.bash_aliases, then log out and back in to affect changes
#Aliases to quickly toggle xdebug
alias xoff='sudo phpdismod -s cli xdebug; sudo /etc/init.d/php7.0-fpm restart'
alias xon='sudo phpenmod -s cli xdebug; sudo /etc/init.d/php7.0-fpm restart'

export XDEBUG_CONFIG="idekey=artisan"
export PHP_IDE_CONFIG="serverName=homestead"

PHPStorm Configuration

Using Zero-Configuration Debugging

  • Add Remote PHP interpreter (Global: should only need to be done once)
    • Vagrant option auto-configures mostly, /usr/bin/php for PHP interpreter path
    • Ensure PHPStorm sees your debugger (should read Xdebug 2.4.0 or similar)
  • Add homestead server (Per project)
    • Host: (vagrant host name)
    • Debugger: Xdebug
    • Use Path mappings: map project root to webserver root
  • Add artisan PHP Remote Debug configuration (Per project)
    • Server: homestead
    • ide key: artisan

Other tooling

For chrome, install xdebug helper extension For other REST clients, you'll need to add the XDEBUG_SESSION_START parameter to your request manually, like so

Debugging Process

  • Set breakpoints in PHPStorm as desired
  • Click Run->Start Listening for PHP Debug Connections
  • Optionally, check Run->Break At First Line in PHP Scripts to step into your code (this might be overkill for Laravel)
  • Interact with your code via cli (php artisan ...), REST client, or web browser (to debug controllers and such). Breakpoints should now be hit!
  • Click Run->Stop Listening for PHP Debug Connections to stop debugging and return your app to run normally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment