Skip to content

Instantly share code, notes, and snippets.

@yuriteixeira
Created October 14, 2015 10:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriteixeira/560f447c0ff5be9f2d36 to your computer and use it in GitHub Desktop.
Save yuriteixeira/560f447c0ff5be9f2d36 to your computer and use it in GitHub Desktop.
Xdebug + Tests + IntelliJ
  • SSH to your machine like this: ssh -R 9000:localhost:9000 your.remote.machine
  • Ensure you have Xdebug installed and configured with xdebug.remote_enable=1
  • Add this snippet to your .bash_profile or similar shell init script:
# XDebug  
function xdebug-start {
	xdebug_site=$1
	xdebug_host=$2
	xdebug_port=$3
	xdebug_idekey=$4

	if [[ -z $xdebug_site ]] then
		xdebug_site="site.dev"
	fi

	if [[ -z $xdebug_host ]] then
		xdebug_host="127.0.0.1"
	fi

	if [[ -z $xdebug_port ]] then
		xdebug_port="9000"
	fi

	if [[ -z $xdebug_idekey ]] then
		xdebug_idekey="PHPSTORM"
	fi

	export PHP_IDE_CONFIG="serverName=$xdebug_site"
	export XDEBUG_CONFIG="remote_host=$xdebug_host remote_port=$xdebug_port idekey=$xdebug_idekey"
}

alias xdebug-stop="unset XDEBUG_CONFIG && unset PHP_IDE_CONFIG"
  • Set your debug config in IntelliJ naming it to site.dev and mapping your local directory to your remote directory (Menu Run > Debug...)

step1

step2

  • Start listening to debug connections clicking in the menu Run > Start listening...
  • Set a breakpoint in your code in IntelliJ
  • Run in the SSH terminal: xdebug-start
  • Run your tests in the SSH terminal (in fact, it can work to any CLI php script also)
@baselica
Copy link

Change the ifs to:

    if [[ -z $xdebug_site ]]; then
        xdebug_site="site.dev"
    fi

    if [[ -z $xdebug_host ]]; then
        xdebug_host="127.0.0.1"
    fi

    if [[ -z $xdebug_port ]]; then
        xdebug_port="9000"
    fi

    if [[ -z $xdebug_idekey ]]; then
        xdebug_idekey="PHPSTORM"
    fi

for compatibility issues.

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