The Cody Humpwhistle Blog

linux and crypto currency podcaster

Category Archives: programming

Setup xdebug with remote php debugging – [phpstorm]

How about my life story, that would be a great introduction wouldn’t it? If you’d rather just see what the fuck I did to get this shit working, scroll down to the first embolden text (that’s text that is in bold for the stupid fuckers like me).

Okay, now they’re out the way, life-story time bitches’. A few years ago, I tried to get vim and xdebug working – as all the cool kids use breakpoints and step-through debugging (You’ve got to be seen in the terminal if you’re programming, right?). It was working, in a fashion. Vim – easy peasy, but xdebug, was a bit of a challenge. I could mark a breakpoint, start debugging and step through the code for the most part.

My development environment using git is hosted on the same remote server as the live php site, and when I commit the code, some git pre-commit shit goes down and merges it with the live site. That wasn’t a big deal, as I’m actually developing on that same remote site (via ssh) using vim anyway, so it was relatively smooth. That is, when the xdebug shit was working. After setup, I’d develop for a period of time without having to debug, and then when I came back to needing it to work, it just wouldn’t. Well, not in the sense I needed it to. Code wouldn’t be executing how I’d expect, I’d drop into debugging mode only to be met with screen tearing through tmux/vim, with CTRL-L just moving some random chars around the screen.

It “worked” but it just wasn’t making my job easier, and I’m already a slow developer – any slower and project would start going backwards. Anyhow, I reverted back to dump and die as my debug of choice and thought “fuck it, do what works for you, fuck the developer elitist who swear by these {standard} debug practises”. And I continued on my merry way.

Until recently, I’ve been working on something that would take anyone else an afternoon, but in typical Cody fashion I’ve been working on it for weeks. Got to a point where the code just wasn’t doing what I was expecting. And even after dropping a dump and die, I couldn’t figure out what was going wrong.

Now I have a friend who programs properly. And he mentioned he was looking at moving to a linux development environment and asked some tips and specifically mentioned stepping through code. Without going into a whole new story, the question was fresh in my mind. He gets paid to program, does it as a job. And he steps through code and thinks it’s important enough to add as a key attribute to setting up a new development environment. And here I am, selling vim and the terminal because it’s “cool”, and really, I’m not the one who’s ahead here.

So I’m scratching my head as my usual dump and die isn’t pointing me the way to amarillo. Fuck.

Could really do with being able to step through the code

Fuck it. What are the kids using these days? Now – the story’s being going on for far too long, but as you can probably guess, I settled on phpstorm.

How the fuck do I set phpstorm to work with remote debugging?

Painfully was the answer. Not because every guide online sucks, but because I just couldn’t visualise how it was all going to come together. So even when they were talking about remote port tunnelling with ssh, although I’ve done it countless times, I couldn’t see which way I was supposed to be forwarding ports. From local to remote, or do I need to forward my ports, scene as I’m the one running the phpstorm software.

Anyway, I got this bundle of joy working. And to help ingrain it in my mind, and get some cheap SEO points, I thought I’d detail the process here.

The How

  1. Follow whatever process you want to get xdebug setup, we want to end with something like this:
  2. Setup a remote SSH tunnel. Mine looks like this (I use mobaxterm, because I’m coool):
    1. Make sure it’s connected.
  3. Click the phone so it’s green both sides:
  4. Install a browser plugin that sends xdebug strings when you make a request:
  5. Set a breakpoint in your code within phpstorm
  6. Enable the xdebug browser helper addon after loading the webpage your debugging, for me it’s which links to the un-commited git code I’m still working on.

Bingo, bango, bongo. When refreshing the page it should catch the debug process within phpstorm.