Xdebug Cli Phpstorm



Phpstorm

Xdebug Phpstorm Cli

CliPhpstorm setup xdebug

There is no clash between xdebug port and php-fpm. The port is the one that the xdebug client (PhpStorm, in this case) will use to listen, and since the client and php-fpm are not running on the same machine (php-fpm runs within a container, the client on the container host), they never clash. Instruct XDebug to connect back to the IP where web request came from. Instruct XDebug to connect to host.docker.internal for command line execution or whenever “connect back” is not possible. Set PHPIDECONFIG env variable to serverName=localhost. This will tell your PhpStorm which server configuration to use. See next step for details.

In host:

Phpstorm Setup Xdebug

Configure phpstorm: In Settings Languages & Frameworks PHP Servers create a new entry. Give it a name (e.g. Localhost) and set the Host to 'localhost' (needs to match the serverName defined in your PHPIDECONFIG environment variable. Set the port to 80 and choose Xdebug as a debugger. Currently PhpStorm supports two debug extensions, namely Xdebug and Zend Debugger. Before start debugging command line scripts you need to configure your development environment: the PHP interpreter and PhpStorm. We keep the other default parameters to keep the configuration as minimal as possible. So, with this setup, the port used by Xdebug is 9000 and the default IP address is 127.0.0.1. Check out the xdebug.remotehost and xdebug.remoteport parameters in the documentation. Now, let's check the configuration inside PHPStorm.

Phpstorm Xdebug Not Working

Phpstorm xdebug not working
  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 0777 /usr/bin/debug
  5. Run your script prefixed with debug:
    • $ debug app/console cache:clear
  6. Debugger window should open in IDE