How to use Xdebugger to debug PHP Built-in Web Server?

Hi all, I have a PHP Built-in Web Server configuration and I cannot get Xdebug to work for setting breakpoints in terms of debugging. I am doing this for a Laravel project. Basically I have installed Xdebug with brew install php54-xdebug for my PHP installation, set remote_enable = On in my php settings. In the PHP Debug settings I have the Xdebug port set to 9000 allowing external connections and in the DBGp Proxy settings I have the IDE key set to my username (which is the default), the host set to local and the port set to 8000 (the port that the built-in web server uses). With this however if I set a break point nothing happens, and I have tried toggling listen for incoming debug sessions and nothing works. Can someone let me know what they did to get this to work?

Thanks,
Darren

12 comments
Comment actions Permalink

Hi,

Please check out these articles first of all:
http://confluence.jetbrains.com/display/PhpStorm/Debugging+PHP+Applications.

If it still don't work, please send here a couple of screenshots and php.ini config.

0
Comment actions Permalink

Hi, below are the screenshots. I install xDebug and set xdebug.remote_emable = On, it uses localhost with port 9000. I also set the DBGp Proxy to use IDE key INTELLIJ, host localhost, and port 9000. Then I installed the Bookmarklets to use that key. I then hit the run for my built in server and hit the Start Listen PHP Debug Connections, set a breakpoint in my code and opened my browser with the bookmarket having the Start hit. Nothing happened. Here are screenshots, what am I doing wrong?



Attachment(s):
Screen Shot 2013-12-17 at 10.39.03 AM.png
Screen Shot 2013-12-17 at 10.38.44 AM.png
Screen Shot 2013-12-17 at 10.38.32 AM.png
Screen Shot 2013-12-17 at 10.38.17 AM.png
Screen Shot 2013-12-17 at 10.38.03 AM.png
0
Comment actions Permalink

1) Do not use Xdebug Proxy -- I doubt you have it installed and running on your computer (I do not think you actually know how it works and what it is for, otherwise you would not attempt to configure it for your environment).

2) Make sure that you have set breakpoint in correct file (or ... that you are executing the correct file). It did not worked for me as well .. simply because I was executing wrong file (different to where I have breakpoints set).

3) Instead of trying this straight away on real complex app, try configuring it for simple script/project first -- it will be easier to figure out what could possibly go wrong

a) Create brand new project with simple script, something like (index.php):

<?php
$a = 5; // breakpoint here

$b = 3;
$c = $a + $b;
echo 'Result: ', $c;

b) Configure and launch your built-in webserver (use slightly different port to avoid confusion between projects, e.g. 8001)
c) Set breakpoints
d) Launch debugging:

  • activate that phone-handle icon;
  • navigate to this site in browser (e.g. localhost:8001/index.php);
  • use "Start debug" bookmarklet (or xdebug browser extension, if you have one)
  • refresh the page so xdebug kicks in


If still nothing -- enable xdebug logging (xdebug.remote_log = /path/to/log/file) and see what it will say after each attempt.

0
Comment actions Permalink

In the log I get:

Log opened at 2013-12-18 00:24:56
I: Connecting to configured address/port: localhost:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///Users/darren/Development/Project/Site/server.php" language="PHP" protocol_version="1.0" appid="2275" idekey="darren"><engine version="2.2.3"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2013 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

Log closed at 2013-12-18 00:24:57


But my breakpoints don't do anything. Its starting to seem that this type of debugging incompatible when running the PHP built in web-server. The breakpoints should work regardless if I am on IntelliJ right?

0
Comment actions Permalink
The breakpoints should work regardless if I am on IntelliJ right?

They should. Unless there was a bug and you still using old version of the PHP plugin. I may only suggest to try that simple test project in actual PhpStorm (latest version is 7.1 build 133.326, released today/yesterday).

In the log I get:

It's way to short. This is what I got when script got executed but not breakpoint was set (on purpose). As you can see it's MUCH longer. Your one does not even tries to register any breakpoint or any activity at all.

Possibly you have truncated/edited your log file too much. If so:
1) please post original (non-modified one)
2) provide screenshot of your web-server configuration (for this project) -- also show what command IDE executes when launches it (I must see original file names).

Log opened at 2013-12-18 00:41:40
I: Connecting to configured address/port: 127.0.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///E:/Projects/web/_idetest/test.php" language="PHP" protocol_version="1.0" appid="3988" idekey="phpStorm"><engine version="2.2.3"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2013 by Derick Rethans]]></copyright></init>

<- feature_set -i 0 -n show_hidden -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="0" feature="show_hidden" success="1"></response>

<- feature_set -i 1 -n max_depth -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="max_depth" success="1"></response>

<- feature_set -i 2 -n max_children -v 100
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_children" success="1"></response>

<- status -i 3
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="status" transaction_id="3" status="starting" reason="ok"></response>

<- step_into -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="4" status="break" reason="ok"><xdebug:message filename="file:///E:/Projects/web/_idetest/test.php" lineno="2"></xdebug:message></response>

<- eval -i 5 -- aXNzZXQoJF9TRVJWRVJbJ1BIUF9JREVfQ09ORklHJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="5"><property address="19781684" type="bool"><![CDATA[0]]></property></response>

<- eval -i 6 -- aXNzZXQoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="6"><property address="19781684" type="bool"><![CDATA[1]]></property></response>

<- eval -i 7 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="7"><property address="19781684" type="string" size="9" encoding="base64"><![CDATA[bG9jYWxob3N0]]></property></response>

<- eval -i 8 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9QT1JUJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="8"><property address="19781684" type="string" size="2" encoding="base64"><![CDATA[ODE=]]></property></response>

<- eval -i 9 -- KHN0cmluZykoJF9TRVJWRVJbJ1JFUVVFU1RfVVJJJ10p
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="9"><property address="19781684" type="string" size="9" encoding="base64"><![CDATA[L3Rlc3QucGhw]]></property></response>

<- stack_get -i 10
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stack_get" transaction_id="10"><stack where="{main}" level="0" type="file" filename="file:///E:/Projects/web/_idetest/test.php" lineno="2"></stack></response>

<- run -i 11
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="11" status="stopping" reason="ok"></response>

<- run -i 12
Log closed at 2013-12-18 00:41:40

0
Comment actions Permalink

Mine command is:
/usr/local/bin/php -S localhost:8000 -t /Users/darrenlabey/Development/Project/Site/public /Users/darrenlabey/Development/Project/Site/server.php

That server file is very minimal as its the router.



Attachment(s):
Configuration.jpg
0
Comment actions Permalink

And xdebug.log file for this site?

Or is it EXACTLY the same as previous one?

0
Comment actions Permalink

Same as before.

0
Comment actions Permalink

Well .. I'm making my comments purely based on the info YOU have provided. And for me it's either you have edited the log .. or you do have some specific configuration of your OS/file system (symbolic links)?

Based on info from xdebug log and command used to launch PHP's built-in web server, I do see the difference between
/Users/darren/Development/Project/Site/server.php
and
/Users/darrenlabey/Development/Project/Site/server.php

As it stands right now and based on the above, xdebug is trying to debug first one, while your project is located in another folder. This makes original file OUTSIDE of the project (file is not mapped to project files).

You have to remember that IDE works with path as is while xdebug always works with final/resolved paths. If you have symbolic link (e.g. /Users/darrenlabey -> /Users/darren) then you will have to properly setup path mappings in "Preferences | PHP | Servers".

0
Comment actions Permalink

I was simply trying to remove my last name, they are the same paths. The server.php file is a Laravel server routing file for PHP's built in web server to faciliate routing requests to proper controllers. I've followed all of JetBrains' tutorials to try to get this to work on IntelliJ and have come to the conclusion I am using the wrong Run configuration (PHP Built-in WebServer) or that this does not work on IntelliJ. I tried to setup a PHP Web Application configuration with Xdebug selected as the debugger as well as to use the PHP Built-in WebServer configuration when that is ran, thinking because then I had a debug button. I can see the log being actively filled, its just that the breakpoints do not work, and I am on the right file as I have a breakpoint set right before an exit statement.

0
Comment actions Permalink

I gave you a suggestion to try to debug simple project first instead of going to your real one straight away. Did it worked?

Once again -- without real logs I cannot help you here any further. Maybe somebody else can (one of the devs, for example).

0
Comment actions Permalink

Hello!

Configure xdebug to attempt to debug

xdebug.remote_enable = 1

0

Please sign in to leave a comment.