Friday, October 4, 2013

Remote debugging your php project with Netbeans and Xdebug via ssh

Recently I needed to remotely debug my app. Naturally attempt failed. And I began to look for what is wrong.
To make the story short, you need to pay attention to following things:
1. Ensure that xdebug is properly configured on your remote server. You can google 'netbeans xdebug' for this issue.
2. In your netbeans open project properties. Go to 'Run options' then at right bottom corner click 'Advanced'. Now you can see debugging config.
3. Now fill 'Path mapping' config. Key rule here is in server path: path must be real path to the project web dir (where you index.php locsted) Path need to be without symlinks. It is important.
4. End finally at the right side fill path to project on your dev machine.
5. Optionally you can tick Run browser when debugging. End you done with config.

If debugging session is in state 'waiting for connection' you have something blocking between  you and your remote server. In this case you have to make sure that 9000 port is open on both sides. Also if you behind NAT, you need to set up port forwarding as well.

But, if you have ssh access to your application server. Than life will be much better, and is simple as run this command:

ssh -R 9000:localhost:9000 user@server

It will forward remote 9000 port to your computer 9000 port via ssh tunnel. In this case you need to set xdebug config param xdebug.remote_host=localhost cause it actually will be forwarded to you via ssh port forward feature. Thats it.

If you don't see green line after you start debugging session then simply ask me in the comments. I'll try to help.

1 comment: