Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for command line debugging? #3

Closed
pirog opened this issue Jul 7, 2013 · 13 comments
Closed

Support for command line debugging? #3

pirog opened this issue Jul 7, 2013 · 13 comments

Comments

@pirog
Copy link

pirog commented Jul 7, 2013

Hey there,

Great plugin!

I'm trying to debug a command line utility called drush... which is a php based shell for drupal.

Generally it is invoked on the command line. Is there anyway i could use this plugin to debug? I've tried playing around with the sublime settings and settings some environmental variables in the terminal as per http://stackoverflow.com/questions/1947395/how-can-i-debug-a-php-cli-script-with-xdebug but havent been able to get anything.

@martomo
Copy link
Owner

martomo commented Jul 7, 2013

Before you run your script on command line, you need to set an Environment Variable with the IDE key to initiate a debugging session.

Windows

set XDEBUG_CONFIG="idekey=sublime.xdebug"
php myscript.php

UNIX

export XDEBUG_CONFIG="idekey=sublime.xdebug"
php myscript.php

Make sure you have Xdebug properly configured in both your php.ini, the one for Apache and CLI, that way you avoid any unexpected behaviour when debugging.

With SublimeTextXdebug you can add/remove breakpoints, another way is to set the breakpoint in your PHP code with the following function xdebug_break().

@pirog
Copy link
Author

pirog commented Jul 7, 2013

yeah i did that. no dice.

does this work for you?

@martomo
Copy link
Owner

martomo commented Jul 7, 2013

Yeah it worked for me, but I ran the PHP script on the same system (Windows) as Sublime Text.

What is your environment?

  • Is the command line script on a remote server;
  • What operation system(s) are you using;
  • Which version of Sublime Text do you have;

@pirog
Copy link
Author

pirog commented Jul 7, 2013

Have a MacOSX 10.8 machine with a Ubuntu 12.04 VM running as a local dev web server. Using ST2.

I've tried running the script both on MacOSX and Ubuntu and have set XDEBUG_CONFIG="idekey=sublime.xdebug" on both.

I have managed to get this to work using MacDGBp which is a rather old XDEBUG client.

@pirog
Copy link
Author

pirog commented Jul 7, 2013

What does your project.sublime-project file look like for CLI debugging? Is there anything special that needs to be done there?

@martomo
Copy link
Owner

martomo commented Jul 7, 2013

Can you post your Xdebug configuration from the *.ini in /etc/php5/cli and /etc/php5/apache2 located on your Ubuntu server.

What is the absolute path of your PHP CLI script on Ubuntu and on OS X?

I don't have any settings configured in *.sublime-project, but I think you will need to configure the path_mapping entry in your *.sublime-project.

@pirog
Copy link
Author

pirog commented Jul 8, 2013

Sure. I can get xdebug to work fine when debugging a website in ST2 and also CLI debugging with another app. Using nginx (php5-fpm) instead of apache but both have the same settings for xdebug:

zend_extension=/usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable=On <- have also used 1 here
xdebug.remote_host=host.kala <- this maps to the IP of the host/macosx machine
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=1
xdebug.remote_autostart=On <- have also used 1 here

path on ubuntu is /usr/share/drush/drush.php, mac is /home/vagrant/kalabox/drush/drush.php.

this is a little funky since you actually run "drush COMMAND" instead of directly calling drush.php but "drush" is just a bin/bash/bat wrapper for drush.php. I've gotten "drush COMMAND" to work with xdebug using macDGBp. That all said ive also tried with a very simple test script and also no dice.

I've got the appropriate path mapping in its *.sublime-project.

@martomo
Copy link
Owner

martomo commented Jul 9, 2013

When reproducing this issue on a desktop running Ubuntu 12.10 and on a virtual machine running Ubuntu 13.04, I was able to debug drush from both machines in Sublime Text located on Windows 7.

What I experienced as an issue when trying to debug drush was that when I defined the XDEBUG_CONFIG environment variable as normal user, then ran drush as root through sudo drush, the root user does not have the environment variable XDEBUG_CONFIG that was defined by the normal user and sudo export does find command export.

This is what did when I wanted to debug drush.

# Switch to root user, to make sure the environment variables will be set for root
sudo su
# Set idekey to initialize session and host where to connect session
export XDEBUG_CONFIG="remote_host=host.kala idekey=sublime.xdebug"
# Check if configuration is succesfully configured
php --ri Xdebug
# Start debugging
drush

To verify if the debugging session was succesful you should see the following text in your log file which is configured in remote_log.

I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: host.kala:9000. :-|
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///usr/share/php/drush/drush.php" language="PHP" protocol_version="1.0" appid="10574" idekey="sublime.xdebug"><engine version="2.2.3"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2013 by Derick Rethans]]></copyright></init>

Below are the settings I configured on both machines.

/etc/hosts

127.0.0.1       localhost
127.0.1.1       ubuntu
# Mapped IP address of Windows 7 machine to host.kala (similar to your OS X)
172.22.60.8     host.kala

/etc/php5/cli/php.ini

[xdebug]
zend_extension=/usr/lib/php5/20100525+lfs/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = "dbgp"
xdebug.remote_mode = req
xdebug.remote_connect_back = 1
xdebug.remote_log = "/tmp/xdebug_cli.log"

Does your .sublime-project look something like this?

{
    "ide_key": "sublime.xdebug", 
    "path_mapping": {
        "/usr/share/drush/" : "/home/vagrant/kalabox/drush/"
    }, 
    "port": 9000
}

Note: You sure the path to drush on Ubuntu is not /usr/share/php/drush/?

@pirog
Copy link
Author

pirog commented Jul 9, 2013

Thanks @martomo! very helpful. i'll give it a shot and see if i can get it to work. will report back as soon as i try it out, hopefully sometime friday.

definitey /usr/share/drush... using a custom build https://github.com/kalamuna/kalastack

@martomo
Copy link
Owner

martomo commented Jul 13, 2013

@pirog did you manage to get the command line debugging to work?

@martomo
Copy link
Owner

martomo commented Jul 15, 2013

I will close this issue as I've been able to debug command line without any issues and I think the above comment should help with which steps to undertake when debugging a command line script (drush).

@martomo martomo closed this as completed Jul 15, 2013
@pirog
Copy link
Author

pirog commented Jul 15, 2013

@martomo sorry for the delay here but yes i was able to get this to work as expected. not sure what was happening before...

@richardbporter
Copy link

Sorry to comment on an old issue, but was there anything specific that was causing this? I seem to have the same problem.

I can debug through a browser just fine, but triggering any PHP script through the CLI does not work. I'm debugging remotely from OSX to a Vagrant box running CentOS 6.5.

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

No branches or pull requests

3 participants