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).
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.
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!
Xdebug is a PHP extension which provides debugging and profiling capabilities. It uses the DBGp debugging protocol. ↩︎
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. ↩︎
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. ↩︎