These days I’ve been coding some commands to handle a newsletter with a work queue, so I needed the XDebug’s benefits to debug the commands. In a previous post I published the talk I did in Symfony VLC about the goodies of XDebug, but it lacked a part about debugging php scripts.
I usually use a dev server with Vagrant and provisioned with Puppet as dev environment. To get the basic configuration of the box I use Puphpet. Then I will explain what I did to use XDebug in this environment, that it’s pretty straight forward:
- Configure XDebug to enable the profiler
- Configure console’s environment
The base configuration that provides Puphet normally it’s like this:
1 2 3 4 5 6 7
A remarkable point of this configuration is that with
xdebug.remote_connect_back=0 we tell XDebug that we will provide the IP address where it has to send the debug info. XDebug looks for
REMOTE_ADDRESS if we connect through HTTP but in our case we would have to configure it via PHP config (
xdebug.remote_host) or in our console environment.
In this case, as I am using a Vagrant box, I configure the host IP directly. All petitions will come from here.
In one hand we have to configure a server name in the environment. Thus our IDE will look for the path mapping configuration of this server.
In the other hand we have to tell XDebug to start debugging.
To start debugging at this point is as simple as to set a breakpoint at our IDE and execute the script at the server.