search
HomeDevelopment ToolsVSCodeA brief discussion on the method of vscode+xdebug for PHP debugging

This article will introduce to you how to use xdebug to debug PHP in vscode. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A brief discussion on the method of vscode+xdebug for PHP debugging

Debugging is divided into two types: local debugging and remote debugging

[Recommended study: "vscode tutorial》、《PHP video tutorial》]

Local debugging

Local debugging requires prerequisites:

  • First, install xdebug extension in php. If php has been installed, you can use php -m | grep xdebug to check whether xdebug is installed.

    A brief discussion on the method of vscode+xdebug for PHP debugging

    If xdebug is not installed, you can use apt-get install php-xdebug to install it.

    Then use php --ini to find the location of the php.ini file.

    A brief discussion on the method of vscode+xdebug for PHP debugging

Then modify the php.ini file and add the following two lines

xdebug.remote_enable = 1
xdebug.remote_autostart = 1

If there is no vim in docker, you can use apt-get install vim to install vim.

  • Second, install the PHP Debug extension in vscode.


    A brief discussion on the method of vscode+xdebug for PHP debugging

    Then add the local PHP execution path in the settings.json file of vscode. The Linux system can use whereis php to find the path of the php command:


    A brief discussion on the method of vscode+xdebug for PHP debugging

Then open the launch.json file:

A brief discussion on the method of vscode+xdebug for PHP debugging

There is already a default in it Added xdebug listening on port 9000.

At this time, just add a breakpoint on a certain line of the php file.

Remote debugging

Debug the PHP project on the remote host , need to change three places:

First, modify the xdebug.ini file on the remote host

Use php --ini to find the location of xdebug.ini:

php --ri xdebug You can view the contents of the xdebug.ini file. If your xdebug.ini is configured in php.ini, modify php.ini.

A brief discussion on the method of vscode+xdebug for PHP debugging

Change the corresponding remote_host and remote_port to your own ip and port. For example, the port here is 9020.

Second, modify the launch.json file in vscode

Add a new listening configuration for port 9020 in the launch.json file of vscode, for example:

A brief discussion on the method of vscode+xdebug for PHP debugging

The name in it can be chosen casually. The port should be set to the remote corresponding port, and the pathMappings should be set to the directory corresponding to your own project.

Third, open the remote debugging interface of your computer

For example, my debugging port here is 9020, open the advanced settings of the firewall:

A brief discussion on the method of vscode+xdebug for PHP debugging
A brief discussion on the method of vscode+xdebug for PHP debugging

Then add support for port 9020 in the new rule: Port->TCP->Specific port support 9020->Just go to the next step. You can also add it to outbound rules. Support for port 9020.

The configuration is now successful. At this time, add a breakpoint and run the remote project to see that it has been broken locally. Now you can happily find bugs:).

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of A brief discussion on the method of vscode+xdebug for PHP debugging. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
Visual Studio: A Powerful Tool for DevelopersVisual Studio: A Powerful Tool for DevelopersMay 08, 2025 am 12:19 AM

VisualStudio is a powerful IDE developed by Microsoft, supporting multiple programming languages ​​and platforms. Its core advantages include: 1. Intelligent code prompts and debugging functions, 2. Integrated development, debugging, testing and version control, 3. Extended functions through plug-ins, 4. Provide performance optimization and best practice tools to help developers improve efficiency and code quality.

Visual Studio vs. VS Code: Pricing, Licensing, and AvailabilityVisual Studio vs. VS Code: Pricing, Licensing, and AvailabilityMay 07, 2025 am 12:11 AM

The differences in pricing, licensing and availability of VisualStudio and VSCode are as follows: 1. Pricing: VSCode is completely free, while VisualStudio offers free community and paid enterprise versions. 2. License: VSCode uses a flexible MIT license, and the license of VisualStudio varies according to the version. 3. Usability: VSCode is supported across platforms, while VisualStudio performs best on Windows.

Visual Studio: From Code to ProductionVisual Studio: From Code to ProductionMay 06, 2025 am 12:10 AM

VisualStudio supports the entire process from code writing to production deployment. 1) Code writing: Provides intelligent code completion and reconstruction functions. 2) Debugging and testing: Integrate powerful debugging tools and unit testing framework. 3) Version control: seamlessly integrate with Git to simplify code management. 4) Deployment and Release: Supports multiple deployment options to simplify the application release process.

Visual Studio: A Look at the Licensing LandscapeVisual Studio: A Look at the Licensing LandscapeMay 05, 2025 am 12:17 AM

VisualStudio offers three license types: Community, Professional and Enterprise. The Community Edition is free, suitable for individual developers and small teams; the Professional Edition is annually subscribed, suitable for professional developers who need more functions; the Enterprise Edition is the highest price, suitable for large teams and enterprises. When selecting a license, project size, budget and teamwork needs should be considered.

The Ultimate Showdown: Visual Studio vs. VS CodeThe Ultimate Showdown: Visual Studio vs. VS CodeMay 04, 2025 am 12:01 AM

VisualStudio is suitable for large-scale project development, while VSCode is suitable for projects of all sizes. 1. VisualStudio provides comprehensive development tools, such as integrated debugger, version control and testing tools. 2.VSCode is known for its scalability, cross-platform and fast launch, and is suitable for fast editing and small project development.

Visual Studio vs. VS Code: Comparing the Two IDEsVisual Studio vs. VS Code: Comparing the Two IDEsMay 03, 2025 am 12:04 AM

VisualStudio is suitable for large projects and Windows development, while VSCode is suitable for cross-platform and small projects. 1. VisualStudio provides a full-featured IDE, supports .NET framework and powerful debugging tools. 2.VSCode is a lightweight editor that emphasizes flexibility and extensibility, and is suitable for various development scenarios.

Visual Studio: Comparing Free and Paid OptionsVisual Studio: Comparing Free and Paid OptionsMay 02, 2025 am 12:09 AM

When choosing VisualStudio, the free version is suitable for individual developers and small teams, and the paid version is suitable for large enterprises and users who need advanced features. 1. The free CommunityEdition provides basic development tools for individuals and small teams. 2. Paid Professional and Enterprise Editions provide advanced features and support for business environments and large teams.

Visual Studio: A Comprehensive Guide to its FeaturesVisual Studio: A Comprehensive Guide to its FeaturesMay 01, 2025 am 12:14 AM

VisualStudio provides a variety of features to improve development efficiency. 1. Interface and navigation: manage projects through menu bar, toolbar and other components. 2. Code editing and intelligent perception: Provide code completion and formatting tools. 3. Debugging and testing: Support breakpoint settings and variable monitoring. 4. Version control: Integrate with Git and other systems to facilitate team collaboration.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor