I absolutely love XDebug, it’s a tool that no PHP developer should go without! I constantly find myself in contracts where the workplace aren’t using it, and I end up installing and configuring it for them. However, using XDebug alone will only allow one connection at a time. This is fine when we are are developing in an isolated environment, but in many offices an entire team of developers could be working on a server at once! The solution to this is to add an XDebug proxy!
I will assume for this tutorial that you already have XDebug working and can connect with one user.
The first step is to download the debugger proxy itself to the machine running PHP. This can be found here http://code.activestate.com/komodo/remotedebugging/
Now, before you click on the PHP download, DON’T. You actually want the Python one. Download the package for your OS. If you use Linux or Mac, you’ll need python installed too. Windows comes with a binary .exe so Python isn’t required.
Depending whether you are using PHP-FPM or not will determine which port XDebug is currently listening on. PHP-FPM itself runs on port 9000, so if you are using that, your XDebug port will probably be 9001. If you are using PHP as an apache module or whatever, XDebug will probably be listening on port 9000. For the purposes of this article I will assume XDebug is listening on port 9000.
To start the proxy on Windows:
.\pydbgpproxy.exe -d 127.0.0.1:9000 -i 126.96.36.199:9001
To start the proxy on Linux:
export PYTHONPATH=<_Komodo install directory_>/lib/support/dbgp/pythonlib;$PYTHONPATH cd <_Komodo install directory_>/lib/support/dbgp/bin python pydbgpproxy -d 127.0.0.1:9000 -i 188.8.131.52:9001
To start the proxy on OS X:
export PYTHONPATH=<_Komodo install directory_>/Contents/SharedSupport/dbgp/pythonlib;$PYTHONPATH cd <_Komodo install directory_>/Contents/SharedSupport/dbgp/bin python pydbgpproxy -d 127.0.0.1:9000 -i 184.108.40.206:9001
-d is the debugger itself, listening on port 9000 on the same machine
-i is the IDE listener port. The IP itself is actually the external IP of this same machine.
If it’s running, you should see something like this:
proxy> .\pydbgpproxy.exe -d 127.0.0.1:9000 -i 10.227.148.40:9001
INFO: dbgp.proxy: starting proxy listeners. appid: 8080
INFO: dbgp.proxy: dbgp listener on 127.0.0.1:9000
INFO: dbgp.proxy: IDE listener on 10.227.148.40:9001
Now back in PHPStorm (or some inferior product) Goto the DBGp Proxy settings in the tools menu, and select configure. Put your name in the IDE key box, the IP of the PHP server, and port 9001.
Again in the tool DBGp proxy, and click Register IDE. If successful, you should be able to see lines like this:
INFO: dbgp.proxy: Server:onConnect ('10.227.148.38', 60748) [proxyinit -p 9000 -k DEREK -m 1 ]
INFO: dbgp.proxy: Server:onConnect ('10.227.148.38', 60996) [proxyinit -p 9000 -k KPATIL -m 1 ]
And that’s it! Now two or more developers can simultaneously use XDebug at the same time. Have fun!