简体   繁体   English

如何在Ubuntu中使用VSCode IDE调试PHP

[英]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 向导说明快照。

Ubuntu 中 Php 8.1 的 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如下快照

使用 cli 的 php 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 中启动调试器,请参见下面的快照。

在 VS 代码中启动调试模式以侦听 Xdebug

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.

相关问题 使用WAMP和IDE调试PHP - Debug PHP Using WAMP and an IDE 将VSCode与PHP一起使用(七)Ubuntu中的调试器 - Using VSCode with PHP (7) Debugger in Ubuntu 在 VSCode 中使用 Docker 调试 PHP - Debug PHP using Docker in VSCode 如何使用 VSCode / PHP XDebug / PHP Debug Extension 正确设置 VSCode 和 Wampserver 以便能够在断点线上进行调试和暂停? - How to properly setup VSCode and Wampserver to be able to debug and pause on breakpoint line, using VSCode / PHP XDebug / PHP Debug Extension? 使用 VSCode 和 Docker 调试 PHP - Debug PHP with VSCode and Docker komodo IDE-&gt;使用komodo + xdebug进行远程调试php:如何查看$ _SERVER变量? - komodo IDE -> remote debug php using komodo+xdebug: how to watch the $_SERVER variable? 使用远程IDE在远程服务器上调试PHP代码的解决方案 - Solution to debug PHP code on remote server, using remote IDE Cloud9 IDE:如何在调试中运行php测试? - Cloud9 ide: how running php tests in debug? 无法使用已安装自定义PHP 7.2的Vagrant进行调试,以及使用Firefox的VSCode进行调试,VSCode无法进入断点 - Unable to debug using Vagrant with custom PHP 7.2 installed and VSCode using Firefox, VSCode fails to break into a breakpoint VSCode:php-debug设置 - VSCode: php-debug setup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM