When remote debugging PHP on a production server or another distant environment:
Assume that the development PC is within an internal corporate LAN and cannot be accessed directly from the outside.
In this case, create a reverse SSH tunnel to enable communication between the production server and the local PC.
PHP xdebug configuration file on the production server
Example: /etc/php/5.6/apache2/conf.d/20-xdebug.ini
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_port="9000"
xdebug.profiler_enable=0
xdebug.profiler_output_dir="/tmp"
xdebug.max_nesting_level=1000
xdebug.idekey = "PHPSTORM"
When you run phpinfo(), you will see something like "Scan this dir for additional .ini files /etc/php/5.6/apache2/conf.d" which indicates where to find the configuration file.
With the above settings, during debugging (when the URL’s GET parameter includes something like ?XDEBUG_SESSION_START=12345), it will connect to port 9000 on the localhost.
On the development local PC, execute:
$ ssh -R 127.0.0.1:9000:127.0.0.1:9000 user@example.com
This will tunnel the production server's port 9000 to the local port 9000.
Then, when you run the debugger in PHPStorm, it will break at the breakpoints and allow you to debug.
Please ensure that you properly set up the server path mappings, otherwise it will not break properly.
Incidentally, since I use Python's Fabric for deployment, I create the tunnel with a command like this:
@runs_once
def xdebug():
"""
Creates an SSH tunnel for xdebug
"""
local('ssh -R 127.0.0.1:9000:127.0.0.1:9000 {}@{}'.format(env.user, env.hosts[0]))
Comments