in Debug, Environments, PHP

How to XDebug PHP on production or a remote application

Does you ever had an issue that only appears on production environment? Have you ever felt how easy could be to solve an issue if you can debug the live system instead of the localhost that just works fine?

Debugging a live system can be scary, but it is not if you follow the right steps. Follow this How to XDebug PHP on production and please comment.

Server setup

Check if your SSH Daemon have tcp forwarding enabled:$ grep AllowTcpForwarding /etc/ssh/sshd_config
AllowTcpForwarding yes

Please double check that this line it is not commented with an # character, if so edit /etc/ssh/sshd_config  and uncomment it.

Locate where to add xdebug configuration:

root@server1:~# php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/05-opcache.ini,

Edit /etc/php5/cli/conf.d/20-xdebug.ini  and add the following content:

As you noticed you are editing the php5 cli configuration, but at least in Ubuntu 14.04 LTS the apache2 configuration is linked to the clil using soft links.

Developer host setup

On the developer machine we are going to setup a SSH tunnel to the server. This tunnel will redirect the remote (server) port 9000 to the localhost (developer host) port 9000 in order to connect to the local debugger/IDE.

We can do that with a normal ssh command:

ssh -p 22 -R 9000:

Another option is to configure it on your ssh config file ~/.ssh/config  :

Host yourservername
        port 22
        User your-user-name

Once you have everything setup you just have to enable your debugger listener, crete the ssh tunnel and enable your XDebug browser helper.

If you enjoyed How to XDebug PHP on production you may also be interested on How to setup XDebug on OSX.

Please share your thoughts and tricks on the comments.

Write a Comment


  1. Hi

    Thanks for a great tutorial.
    Initially it didn’t work for me, as after changing xdebug settings I forgot to do
    sudo service apache2 restart

    I hope this helps.


  • XDebug and PHP setup for Mac OSX - Albert Sola 18/08/2015

    […] If you like this how-to you may be interested on: How to XDebug PHP on production or a remote application. […]