22
 Oct
       23:03
Author: Rudi Strydom

Sublime Text 2 and Xdebug Setup Issues and work-around
3 days ago

This is not a guide on how to actually install everything to the tee, but rather things to look out for when setting up Xdebug for Sublime. This assumes that you have installed a development server of some sort, whether it be local, vagrant, xamp, mamp or any of the others. This rather extends from the following tutorial http://mwatson.co.uk/debug-php-vagrant-using-xdebug-sublime-text/ .

It also assumes that you have Package Control installed on Sublime. If not you will need to do so https://sublime.wbond.net/installation .

The issues


  • PHP-FPM uses port 9000, and xdebug by default also does.
  • Running a VM, the paths do not match from server to computer.
  • Firewall rules need to be added to allow xdebug traffic from the server
  • Manually set key bindings

  • Porting


    So I am running a Vagrant VirtualBox development host with a LEMP stack (Linux, Nginx, MySQL, PHP-FPM). Something that I didn't know, but figured out is that it's not the IDE "Sublime" connecting to your PHP Server, but rather your PHP server connecting to the IDE when a page is executed. Another issue is that most of the tutorials state that you should install xdebug on PHP and use port 9000, but this port is the same port my PHP-FPM serves content to nginx. So that won't work. In this case you have 2 options, either you can change the xdebug ports, or you can change your nginx ports. Personally, I found it was easier to change the xdebug port to 9999. So nginx is connecting to PHP-FPM via port 9000 as always, and PHP-FPM's xdebug connects to my computer using port 9999.

    So on sublime I set the port to 9999, in my xdebug.ini I set the port to 9999, and ensure that the firewall allows for that port to be accessed.

    Xdebug PHP ini file settings


    /etc/php.d/xdebug.ini
     zend_extension=/usr/lib64/php/modules/xdebug.so
    xdebug.default_enable = 1
    xdebug.idekey = "sublime.xdebug" ; Set the correct ide key
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
    xdebug.remote_port = 9999 ; Connect to to the revised port
    xdebug.remote_handler=dbgp
    xdebug.remote_log="/var/log/xdebug/xdebug.log"
    xdebug.remote_host=192.168.56.1 ; This is my pc's ip from the virtual box


    Sublime Xdebug Settings


    Tools -> Xdebug -> Settings - User
    { "port": 9999 }


    Sublime Project Settings


    You need to set the project settings to enable xdebug for the server url. In my case it is a shorthand dev.art.co.za. The important part is the path_mapping. The left hand is the server side webroot, the right hand my local path of where the files are mapped to.
    "settings": {
    "xdebug": {
    "url": "http://dev.art.co.za/",
    "debug": false,
    "path_mapping": {
    "/var/www/art" : "/home/rudis1261/Vagrant/drpain.local/art"
    }
    }
    }


    Key Bindings



    I used the following key bindings in sublime.

    Prefrences -> Key Bindings - User
    [
    {
    "keys": ["ctrl+f8"],
    "command": "xdebug_breakpoint"
    },
    {
    "keys": ["shift+f8"],
    "command": "xdebug_conditional_breakpoint"
    },
    {
    "keys": ["ctrl+shift+f5"],
    "command": "xdebug_continue",
    "args": {"command": "run"}
    },
    {
    "keys": ["ctrl+shift+f6"],
    "command": "xdebug_continue",
    "args": {"command": "step_over"}
    },
    {
    "keys": ["ctrl+shift+f7"],
    "command": "xdebug_continue",
    "args": {"command": "step_into"}
    },
    {
    "keys": ["ctrl+shift+f8"],
    "command": "xdebug_continue",
    "args": {"command": "step_out"}
    },
    {
    "keys": ["ctrl+shift+f9"],
    "command": "xdebug_session_start"
    },
    {
    "keys": ["ctrl+shift+f10"],
    "command": "xdebug_session_stop"
    },
    {
    "keys": ["ctrl+shift+f11"],
    "command": "xdebug_layout",
    "args": {"keymap" : true}
    }
    ]


    I know it's not very complete, but I am up early and it's late at night. I hope this helps you in any way!



    11
     Oct
    2014

    The hourglass
    11 Oct 2014 20:12, (2 weeks ago)

    08
     Oct
    2014

    It's been a while
    08 Oct 2014 17:51, (3 weeks ago)

    26
     Sep
    2014

    Lost my buttons
    26 Sep 2014 17:52, (5 weeks ago)

    16
     Sep
    2014

    Serenity
    16 Sep 2014 22:20, (last month)

    16
     Sep
    2014

    Ups and downs
    16 Sep 2014 9:11, (last month)

    10
     Sep
    2014

    Life in estimation
    10 Sep 2014 8:37, (last month)

    08
     Sep
    2014

    PHP SPL Auto Loading Classes
    08 Sep 2014 20:33, (last month)

    31
     Aug
    2014

    A walking mind
    31 Aug 2014 23:55, (last month)

    25
     Aug
    2014

    Time heals all wounds
    25 Aug 2014 18:53, (August 2014)

    15
     Aug
    2014

    Trial and error
    15 Aug 2014 21:29, (August 2014)

    04
     Aug
    2014

    Road less traveled
    04 Aug 2014 9:30, (August 2014)

    31
     Jul
    2014

    Time to pack
    31 Jul 2014 9:19, (July 2014)

    12
     Jul
    2014

    Harley Davidson Magic
    12 Jul 2014 21:12, (July 2014)

    10
     Jul
    2014

    Safari Bugging out
    10 Jul 2014 18:33, (July 2014)