Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleStarting the script with Xdebug

Xdebug has various configuration options which we can use to let the PHP interpreter reach out to PhpStorm. These parameters have to be passed to the PHP interpreter using the -d command line switch. A more convenient way will be to set an environment variable so we don't have to provide the -d switches all the time.

Using PHP command line switches

To start our script with debugging we have to:

  1. Set an environment variable that would tell XDebug to connect to IDE:

    Code Block
    Windows:
    set XDEBUG_CONFIG="idekey=123"
     
    Linux / Mac OS X:
    export XDEBUG_CONFIG="idekey=123"

    Here idekey should have a random value.

  2. Launch PHP with several switches:

    Code Block
    php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_connect_back=0 path/to/script.php

     

    You might use 10.0.2.2 instead of 127.0.0.1 with Vagrant (see related SO question).

     

Using an environment variable

To start our script with debugging, we can set an environment variable that configures Xdebug:

Code Block
Windows:
set XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"

Linux / Mac OS X:
export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"

Next, we can start our script like we would normally do:

Code Block
php path/to/script.php

 

 

 

Tip

Optionally, we can use Xdebug's remote_autostart setting to always start a debugging session for every script that is run.

...