by Kevin Schroeder | 8:43 am

I’m working on some code on the command line that I needed to debug.  It’s on a remote machine (well, a VM that doesn’t have a GUI) and so I needed to initiate a remote debugging session from the command line to go to my local copy of Zend Studio.  Thankfully, it’s pretty easy.  Since I need a place to store this command so I can copy and paste it onto the CLI I figured I’d simply blog about it.  Simply execute  this command prior to executing your PHP script.

export QUERY_STRING="start_debug=1&debug_stop=1&debug_fastfile=1&

The only thing you will need to change is the debug_host setting and perhaps debug_port.  Run your CLI script and the debugger will attempt to connect to your local Zend Studio instance.  If you want to discontinue debugging you execute this command.




I use back tics in my export to use the ip that I’ve ssh’d in from as the debug host —

debug_host=`expr “$SSH_CLIENT” : ‘(^[0-9.]*)’`

or for xdebug

remote_host=`expr “$SSH_CLIENT” : ‘(^[0-9.]*)’`

also, if you use phpStorm, be sure to export a SERVER_NAME and REQUEST_URI if you want to do cli debugging

Nov 29.2011 | 08:48 am


    @stm Sure, if you want to be all professional about it 🙂

    Nov 29.2011 | 08:48 am


    @stm Though, IIRC, the use of expr may not always work on all Linux distros as it’s not part of POSIX. Probably doesn’t matter much, though.

    Nov 29.2011 | 09:00 am


      @kschroeder there is probably a more POSIX way of doing it. it is a pretty simple regex

      Nov 29.2011 | 09:02 am


I would suggest adding all that to a php-debug shell command that wraps the execution, makes it easier to fire it up. Like i did here:

Great tip!

Nov 29.2011 | 09:07 am

PHP CLI remote debugging with PhpStorm & Zend Debugger - Richard Tuin's mindspinsRichard Tuin's mindspins

[…] to set up a remote debugging connection to your IDE. In his blog post, Kevin Schroeder explains how to do this. You can do this by running the following command, as copied from Kevin’s […]

Jan 23.2013 | 04:59 pm


A very interesting article on debugging a PHP script. This is very helpful. Thank you for posting.

Feb 12.2014 | 12:28 am


Thanks for sharing this very informative post. It is very useful. Cheers!

Jul 14.2014 | 02:23 am

Leave a Reply

Your email address will not be published. Required fields are marked *