Breakpoints not hit with xdebug, PhpStorm and Laravel 3 / mod_rewrite
Asked Answered
U

3

13

I'm pretty desperate and running out of ideas:

I've configured xdebug and PhpStorm for a Laravel 3 project. Running the project locally on Mac OS X Apache, so PhpStorm and the web application run on the same machine. Configured a virtual host so that localhost.lt points to Laravel's public directory.

Relevant xdebug entries in php.ini:

zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
[xdebug]
xdebug.idekey="PHPSTORM"
xdebug.remote_enable=1
xdebug.profiler_enable=1
xdebug.remote_log=/var/log/xdebug_remote.log
xdebug.remote_connect_back=1

Confirmed that extension gets loaded.

Set up a PHP Web Application debug / run configuration without any path mappings as nothing is symlinked and the folders on the web server and for PhpStorm are exactly the same (as the web server is on the same machine).

When launching via "Debug" from the IDE, xdebug_remote.log correctly shows the breakpoint we've set in one of the files in application/libraries:

<- breakpoint_set -i 5 -t line -f
file:///Users/RalfR/src/livetime/application/libraries/LiveTime.php -n 676
->
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="9230016"></response>

However, when we click a link that invokes the function from the LiveTime.php library, the breakpoint is NOT hit. The log shows:

<- stack_get -i 6 -> 
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stack_get" transaction_id="6"><stack where="{main}" level="0" type="file" filename="file:///Users/RalfR/src/livetime/public/index.php" lineno="14"></stack></response>

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

<- run -i 8
Log closed at 2013-04-22 21:03:57

As many frameworks, Laravel uses .htaccess mod_rewrite to pipe everything through public/index.php. May this be the cause for PhpStorm / xdebug not catching the breakpoint in application/libraries/LiveTime.php as it appears to xdebug that the LiveTime.php script is never executed?

If so, how can we solve this problem?

Undis answered 22/4, 2013 at 21:44 Comment(3)
Also, xdebug_break(); works always, so it's not related to a misconfigured PHP environment.Undis
I'd love to know the answer to this as well!Dumas
I have the exact same issue, only I'm using Symfony and it breaks in some files but not others. xdebug_break(); works everywhere.Salesroom
F
9

You need to set the Path Mappings You don't need to set it for each file. To resolve my issue, I went to the IntelliJ (same for PHPStorm) Preferences > PHP > Servers .. selected my server and set the following (see note 2 below):

enter image description here

NOTE 1: I could also have set the path directly to the project root, but since I am not interested in debugging anything other than my Laravel "public" folder and my application, I only set paths for those 2 folders. After this everything worked perfectly.

NOTE 2: The image shown above is not from the "Settings" dialog referred to in the steps above, but rather from the "Resovle Path Mapping Problem" dialog which presents you with the same map mappings widget which works the same way. Fixings the settings in either place will work. The Resolve Path Mapping Problem dialog will appear if you have no server debug settings to start with and the IDE detects a mapping problem, at which point it will also create the server settings for you.

Fellows answered 31/10, 2013 at 22:42 Comment(4)
Also, another thing I noticed is that sometimes, you may not have the same file in the IDE as on the server when debugging remotely. I have my IDE setup to automatically copy the file being saved, up to the remote host, but this does not always work. So I just manually kick off a file upload, try again, and it will work. This explains why some file will sometimes debug and others will not. The file that does not debug is different from the one on the remote host.Fellows
One last thing .. some break lines won't work at all. For example, if else blocks not wrapped in curly braces cant have the code that would go between the braces, break for break points.Fellows
your solution was close but did not quite work for me. instead I mapped my project's local www folder to /var/www in the PHPStorm settings > Servers.Moor
@Moor Correct, the mappings will differ depending on the project root as well. So if the root of your project gets deployed to the root of the web server then they should match. In my case above the project root is not the same as the web server root but instead, maps to one of many applications placed into the root web directory because we have a separate application (project) for each dir in the web root so that the entire web site is then comprised of multiple but separate projects.Fellows
S
1

For those who are using Netbeans and Laravel, you need to set the "Web Root" as your public folder which located in your project->Properties->Sources.

Edit web root in Netbeans

Stepdame answered 17/5, 2017 at 4:16 Comment(0)
K
0

In my case, the cause of the "breakpoint_set" / "command is not available" problem was disabled xdebug.extended_info option (it is enabled by default but I disabled it for profiling).
Breakpoints do not work then xdebug.extended_info is disabled.
I have got breakpoints worked after reenabling xdebug.extended_info.

Kolnos answered 3/8, 2015 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.