xdebug、PhpStorm 和 Laravel 3 / mod_rewrite 未命中断点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16157276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:43:57  来源:igfitidea点击:

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

laravelxdebugphpstormlaravel-3

提问by Ralf

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.

我已经为 Laravel 3 项目配置了 xdebug 和 PhpStorm。在 Mac OS X Apache 上本地运行项目,因此 PhpStorm 和 Web 应用程序在同一台机器上运行。配置一个虚拟主机,让 localhost.lt 指向 Laravel 的公共目录。

Relevant xdebug entries in php.ini:

php.ini 中的相关 xdebug 条目:

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).

设置一个没有任何路径映射的 PHP Web 应用程序调试/运行配置,因为没有任何符号链接,并且 Web 服务器和 PhpStorm 上的文件夹完全相同(因为 Web 服务器在同一台机器上)。

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:

从 IDE 通过“调试”启动时,xdebug_remote.log 正确显示了我们在应用程序/库中的文件之一中设置的断点:

<- 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:

但是,当我们单击从 LiveTime.php 库中调用该函数的链接时,断点并未命中。日志显示:

<- 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?

与许多框架一样,Laravel 使用 .htaccess mod_rewrite 通过 public/index.php 管理所有内容。这可能是 PhpStorm / xdebug 没有捕获 application/libraries/LiveTime.php 中的断点的原因,因为 xdebug 似乎从未执行 LiveTime.php 脚本?

If so, how can we solve this problem?

如果是这样,我们如何解决这个问题?

回答by MikeM

You need to set the Path MappingsYou 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.

您需要设置路径映射您不需要为每个文件设置它。为了解决我的问题,我转到 IntelliJ(与 PHPStorm 相同)Preferences > PHP > Servers .. 选择我的服务器并设置以下内容(参见下面的注释 2):

在此处输入图片说明

注意 1:我也可以直接设置项目的路径root,但由于我对调试除 Laravel“公共”文件夹和我的应用程序以外的任何东西都不感兴趣,我只为这两个文件夹设置了路径。在此之后,一切正常。

笔记2:上面显示的图像不是来自上述步骤中提到的“设置”对话框,而是来自“解决路径映射问题”对话框,该对话框为您提供相同的地图映射小部件,其工作方式相同。修复任一位置的设置都将起作用。如果您没有要开始的服务器调试设置并且 IDE 检测到映射问题,则会出现“解决路径映射问题”对话框,此时它还会为您创建服务器设置。

回答by Mage2.PRO

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

就我而言,“ breakpoint_set”/“ command is not available”问题的原因是禁用xdebug.extended_info选项(默认情况下启用它,但我禁用了它进行分析)。
断点不起作用然后xdebug.extended_info被禁用。
重新启用xdebug.extended_info.

回答by MS48

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.

对于那些使用 Netbeans 和 Laravel 的人,您需要将“Web Root”设置为位于您的项目->属性->源中的公共文件夹。

Edit web root in Netbeans

在 Netbeans 中编辑 web 根目录