[英]How to debug PHP using VSCode IDE in Ubuntu
I need to debug PHP code using VS Code IDE. We can debug PHP using Xdebug .我需要使用 VS Code IDE 调试 PHP 代码。我们可以使用Xdebug调试 PHP。 So I tried a lots to setup Xdebug for debugging but I failed to use Xdebug using VS Code IDE.所以我尝试了很多来设置 Xdebug 进行调试,但我未能使用 VS Code IDE 使用 Xdebug。
PHP is 8.1
Ubuntu 22.04.1 LTS
Please help me how can I debug.请帮助我如何调试。
Step 1:- Install PHP Debug Extension in VS Code IDE.第 1 步:- 在 VS Code IDE 中安装PHP 调试扩展。
Step 2:- Copy Full output of Phpinfo()
.第 2 步:- 复制 Phpinfo Phpinfo()
的完整 output。 run below Command in CLI for get output of phpinfo().在 CLI 中运行以下命令以获取 phpinfo() 的 output。
php -r "phpinfo();"
Step 3:- open Xdebug wizard Page & paste copied full output of phpinfo()
in the form field.第 3 步:- 打开Xdebug 向导页面并在表单字段中粘贴完整复制的phpinfo()
output。 after the submitting form you will get step by step Instructions related to setup Xdebug in your System.提交表格后,您将获得与在您的系统中设置 Xdebug 相关的分步说明。
In my system currently I used Php 8.1.在我的系统中,我目前使用 Php 8.1。 see below Snapshot of Xdebug Wizard Instructions.请参阅下面的 Xdebug 向导说明快照。
Follow above Instruction which one you will getting from Xdebug Wizard按照上面的说明进行操作,您将从Xdebug 向导中获得哪一个
Note that, above Wizard Instructions is as per my server configuration.请注意,上面的向导说明是根据我的服务器配置。 In your case it may differ than my above snapshot.在您的情况下,它可能与我上面的快照不同。 So, you must need to follow Step 2 & 3.因此,您必须需要遵循步骤 2 和 3。
Step 4:- add below Configuration in your php.ini file.第 4 步:- 在您的 php.ini 文件中添加以下配置。
[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
;Note:- Below Xdebug Path is depends on your OS & your PHP Server.
;So you need to write path of xdebug.so (in Linux)
;OR path of xdebug.dll (in windows)
zend_extension=/usr/lib/php/20210902/xdebug.so
for find Extension Directory for your server (Xampp, Lampp etc. all) then, simply Run php -r "phpinfo();"
要为您的服务器(Xampp、Lampp 等)查找扩展目录,只需运行php -r "phpinfo();"
command then find out extension_dir
as like below snapshot命令然后找出extension_dir
如下快照
OR write <?php phpinfo()?>
in your php file then run that php file & found out extension_dir
in your output page of phpinfo.或者在您的 php 文件中写入<?php phpinfo()?>
然后运行该 php 文件并在您的 output phpinfo 页面中找到extension_dir
。
Step 5:- Restart your Server (Apache).第 5 步:- 重新启动您的服务器 (Apache)。
Step 6:- Install Browser Extension Initiation .第 6 步:- 安装浏览器扩展启动。 then start debugger in your Vs Code IDE see below snapshot.然后在您的 Vs 代码 IDE 中启动调试器,请参见下面的快照。
Now, All Done.现在,全部完成。
for referece I share other source urls作为参考,我分享其他来源网址
refer Xdebug Docs refer for Windows refer this for Linux参考Xdebug Docs参考Windows参考这个Linux
But, before starts debugging your code, if you need to check Xdebug is working proply or not then Follow below Steps.但是,在开始调试代码之前,如果您需要检查 Xdebug 是否正常工作,请按照以下步骤操作。 otherwise you can ignore below steps.否则你可以忽略下面的步骤。
In Xdebug 3+.在 Xdebug 3+ 中。 there is xdebug_info() method exits which return info of xdebug extension.有 xdebug_info() 方法退出,它返回 xdebug 扩展的信息。
write <?php xdebug_info(); ?>
写<?php xdebug_info(); ?>
<?php xdebug_info(); ?>
in your php file & then run this php file.you will get output as like below snapshot <?php xdebug_info(); ?>
在您的 php 文件中,然后运行此 php 文件。您将获得 output,如下图所示
& for check Xdebug works properly for CLI run php -r "xdebug_info();"
& 用于检查 Xdebug 是否适用于 CLI 运行php -r "xdebug_info();"
in cli.在命令行中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.