Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vitaly-los/dd99fd060a4a70abf622caad6a0a9187 to your computer and use it in GitHub Desktop.
Save vitaly-los/dd99fd060a4a70abf622caad6a0a9187 to your computer and use it in GitHub Desktop.
configure Netbeans PHP debugging for a remote server, over a SSH tunnel
Having tripped myself up on multiple occasions setting this up, I’m recording these config steps here for future-me.
Scenario: You have a PHP site running on a remote [Ubuntu 12.04] server, and want to connect your local IDE [Netbeans] to the Xdebug running on that server over a SSH tunnel.
apt-get install php5-xdebug
vi /etc/php5/apache2/conf.d/xdebug.ini
zend_extension=/usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable=On
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
restart apache2
Create remote->local SSH tunnel ssh -R 9000:127.0.0.1:9000 yourname@yourserver.com
Launch Netbeans debugger
The key is that your Netbeans IDE acts as the server in this scenario, listening for incoming connections to port 9000 from the remote server’s XDebug. Thus the tunnel must be from the remote port to your local port, not the other way around.
Some helpful debugging technques
Start ssh with -vv for debugging output
netstat -an | grep 9000
should show something like:
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9000 127.0.0.1:59083 ESTABLISHED
tcp 0 0 127.0.0.1:59083 127.0.0.1:9000 ESTABLISHED
tcp6 0 0 ::1:9000 :::* LISTEN
down vote
If you're running the default apt installation of PHP on Ubuntu 16.04, then it should be PHP7. If I had to guess from php5-xdebug, then I'd say you were using a command intended for Ubuntu 14.04 or older where the default PHP installation was PHP5. You can verify your PHP version with:
php --version
This is what I see:
apt search xdebug
From my relatively fresh Ubuntu 16.04 install without any added PPA's, I get one result:
php-xdebug - Xdebug Module for PHP
So you can install this package by name (note the missing "5" from your command):
sudo apt install php-xdebug
You might also have to restart your webserver. If you're running the stock build of Apache for Ubuntu 16.04:
sudo service apache2 restart
Copy link

ghost commented Sep 4, 2020

Thank you for this information. I just uploaded a video explaining a similar setup. https://www.youtube.com/watch?v=9uf7sUCAcRE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment