Debug PHP with Xdebug in Sublime Text 2 (in Linux mint)

Fri, 2012-11-16 13:29 | by Samuel Lampa

After learning to know about Sublime Text 2, it seems to be a perfect companion to VIM and Eclipse, my other favourite editors/IDE:s. Now I also got it set up to debug PHP scripts with Xdebug :) See for yourself:

Sublime as the perfect companion to VIM and Eclipse

VIM, with some modifications, is perfect for quickly editing scripts while navigating around in the command line, and is also available virtually everywhere.

Eclipse is of course the standard workhorse for development, but sometimes it just feels to heavy, and even the simplest debug session will require setting up a new project with a lot of settings, defining a workspace etc etc. And this is where Sublime comes in.

Sublime is more easy to work with than Eclipse/PyDev, Eclipse/PDT (PHP) etc for a number of reasons:

1. Working with projects and folders

The first thing is how it works with folders and project.

In Sublime, most of the time you don't even need a project. It's enough to open a folder (File > Open folder ..., or "sublime <foldername>" on the command line). This will enable the super nice file opening tool (Ctrl + P), that suggests (and previews in realtime) files as you type (with powerful fuzzy-search), which is really handy when you forgot what that file in your project was named.

On the other hand, setting up a project is also very quick and easy. Just use the "Open Folder" feature as described above, and then go "Project > Save Project As ...". This will add one setting in the project definition: the path to the folder. For configuring Xdebug for PHP debugging (more info on installing the required extensions further below), you just need to add a remote URL setting. This is what I configured for working with my RDFIO SMW extension (accessed with "Project > Edit project"):

2. The code overview / "minitature"

I really like the "code miniature" that you see to the right when having a file open, so that you get a graphical hint of how the file looks, and where you are. Actually in some ways better than a code outline feature like in other editors, since the "graphical structure" of the code seems easier to recognize for the brain, than the logical, at least for me.

3. Easy access to snippets

I hade trying to figure out how to write that method that makes you python file automatically run the main method, so that you can have it at the top ... In sublime I just go Ctrl+Shift+P and start writing "main()" in a python file, and I will find it right away.

4. Powerful auto-completion

Otherwise, I really like the autocompletion of both keywords and brackets and stuff. It is helpful and seem to just work, a lot more often than many other editors.

5. Easy zooming of text

Something I really miss in Eclipse is easy zooming of the text size. I have quite bad eyes, and sometimes need to really zoom up the text size a lot to be able to work at all. Ctrl + + and Ctrl + - is all you need.

5. Vi(m) mode!

I'm very happy about this. The shortcuts for navigating around in vim are quite hard to beat, even for sublime. Happily enough, sublime has the (vi)ntage mode, so that you can use the most common vim shortcuts within sublime itself.

All in all, Sublime makes me feel more productive than I (think) I have been before!

Setting up Xdebug with Sublime Text 2

Setting up Xdebug to work with Sublime requires a few steps, but it's not too cumbersome.

Note, this assumes you use Linux Mint (or maybe some other recent Ubuntu based distro).