2 min read

Debugging PHP with Xdebug over SSH

The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.

— Winston Churchill.

Back in days before Xdebug1 came to light, debugging PHP2 was pretty simple like in C3 on which you use print or var_dump. Today with improving tools and setup, PHP can now be debugged remotely with the help of ssh + xdebug.

To do this first you must connect to the remote development station on where PHP server is located (e.g. PHP direct dynamic server, Nginx, Apache HTTP).

ssh -R 9000:localhost:9000 username_goes_here@hostname_goes_here

The -R stands for return remote callback connection on SSH on which server --(poll)--> host (xdebug server).

After running a remote port forwarding you will need to setup xdebug on the remote server, point it on which address it would bind and listen. For my use case I’d point mine to the loopback address 127.0.0.1 (as I’d only use it for development purposes) on which we setup remote port forwarding to listen to. Edit the php.ini file and at the xdebug configuration make it similar to the sample below.

[xdebug]
zend_extension="/usr/lib64/php/7.1/modules/xdebug.so"
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_log=/tmp/xdebug_remote.log
xdebug.remote_connect_back=0

The most notable part in the config is the xdebug.remote_host and xdebug.remote_port, this is where xdebug would bind. After all the changes have been done, just restart the server (e.g. for Apache HTTP running on CentOS).

service httpd restart

And at our workstation editor with PHP debugger extension we would just point it to 127.0.0.1:9000. That’s all now we can debug PHP remotely.

🧡🧡🧡🧡🧡

Hope you guys enjoyed this article!


  1. Xdebug is a PHP extension which provides debugging and profiling capabilities. It uses the DBGp debugging protocol. ↩︎
  2. PHP is a general-purpose programming language originally designed for web development. It was originally created by Rasmus Lerdorf in 1994; the PHP reference implementation is now produced by The PHP Group. ↩︎
  3. C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. ↩︎