Debugging Xdebug, Laravel, and Vagrant (Homestead) from Sublime

1 min read

The debugging process is a regular process when we are developing any type of application. I am currently working on an application made in Laravel (PHP) and we use Vagrant/Homestead (modified) for the local development of the solution.

I found very little documentation on how to make this work with Sublime Text 3, but after getting it working with PhpStorm I decided to try it with Sublime.

This is what I did to get it working:

First, I had to configure Xdebug on the Vagrant machine, to do this I edited the /etc/php5/fpm/conf.d/20-xdebug.ini file and added the following lines:

xdebug.remote_enable=1
xdebug.remote_port=9001
xdebug.remote_autostart=0
xdebug.remote_connect_back=1

Then, I had to restart PHP-FPM:

sudo service php5-fpm restart

Next step, we must modify our project. To do this, we go to Sublime and create a new project (if we have not already created it) and edit the project, until it looks like this:

{
  "folders":
  [
    {
      "follow_symlinks": true,
      "path": "/Volumes/Secondary/Projects/proyecto"
    }
  ],
  "settings": {
      "xdebug": {
           "url": "http://proyecto.app/",
           "path_mapping": {
              "/home/vagrant/Code/proyecto" : "/Volumes/Secondary/Projects/proyecto",
              "/home/vagrant/Code/proyecto/public" : "/Volumes/Secondary/Projects/proyecto/public",
            },
           "super_globals": true,
           "close_on_stop": true,
           "port": 9001
      }
  }
}

The important lines are those from path_mapping, which made me waste several minutes, but I figured out that something similar needed to be done in PhpStorm.

After editing it, we must restart the Sublime Text. Upon restarting it, we install a package (using Sublime’s Package Control) called “Xdebug Client”.

The last thing we need to do is run Xdebug from Tools -> Start Debugging (Launch Browser) and we are ready. We can try putting a breakpoint nearby and everything should be fine.