docs.devsense.com Open in urlscan Pro
104.42.154.105  Public Scan

URL: https://docs.devsense.com/en/vscode/debug?from=vscode
Submission: On May 05 via manual from US — Scanned from DE

Form analysis 1 forms found in the DOM

Name: mc-embedded-subscribe-formPOST https://devsense.us3.list-manage.com/subscribe/post?u=0a9d3cf50789b9c6b1cff1011&id=5196ce2cd9

<form action="https://devsense.us3.list-manage.com/subscribe/post?u=0a9d3cf50789b9c6b1cff1011&amp;id=5196ce2cd9" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate="">
  <div class="input-group"><input type="email" value="" name="EMAIL" class="form-control email" id="mce-EMAIL" placeholder="Email news to me" required="">
    <div style="position:absolute;left:-5000px"><input type="text" name="b_0a9d3cf50789b9c6b1cff1011_5196ce2cd9" tabindex="-1" value=""></div>
    <div class="input-group-addon" style="padding:0"><button type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="btn btn-default" style="margin:-1px;width:34px;height:34px"><i class="fa fa-chevron-right"></i></button>
    </div>
  </div>
</form>

Text Content

Toggle navigation
 * 
 * Features
 * Docs
 * Blog
 * Support
 * Download
 * Purchase
 * 
 * 
 * * 
   * 
   * Dashboard
   * Edit Profile
   * 
   * Logout

PHP Tools for Visual Studio - Documentation
 * Visual Studio
 * Visual Studio Code

 * Getting Started
 * Code Validation
   * Code Validation
   * Configuration
   * PHP Version Validation
   * Spell Checking
   * Syntax Validation
   * Unnecessary use declarations
 * Debugging
   * Breakpoints
   * Configuring Xdebug
   * Debugging Overview
   * Exceptions or errors
   * Inspecting Data in the debugger
   * Javascript Debugging
   * Multi-user debugging
   * Output Window
   * Remote Debugging
   * Remote Debugging via SSH Tunnel
   * Stepping
   * Troubleshooting
   * Using Callstack
 * Editor
   * Auto Import
   * Blade
   * Code Completion
   * Outlining
   * PHPDoc Comments
   * Regular Expressions
   * Smart Indenting
   * Smarty
   * Suggestions
   * Syntax Highlighting
   * Task List
   * Twig
   * Word Highlighting
 * Installation
   * Installation Instructions
   * Installing PHP
   * Product Activation
   * Product Offline Activation
   * Subscriptions
   * Uninstall
   * Update
 * Navigation
   * Class View
   * F1 Help
   * Find All References
   * Go To Brace
   * Go To Definition
   * Navigate To
   * Navigation Bar
   * PHAR Archives
   * Solution Explorer
 * Project
   * Composer
   * Configuration
   * Events
   * New Project
   * New Project from Composer
   * New Project from Existing Code
   * New Project from Remote
   * Project Validation
   * Remote Explorer
 * Testing
   * PHPUnit Package
   * Run and Debug Tests
   * Test Configuration
   * Test Explorer
   * Writing Test Case
 * Troubleshooting
   * ActivityLog.xml
   * Feedback

 * Configuration
 * Getting Started
 * PHP Version
 * Problems
 * Test Explorer
 * Debug
   * DBGp Proxy
   * Debug Overview
   * Docker Setup
   * Launch Profiles
   * Xdebug on Linux
   * Xdebug on Mac
   * Xdebug on Windows
 * Editor
   * Auto Import
   * Code Actions
   * Code Completion
   * Code Editor Overview
   * Code Formatting
   * Code Lens
   * HTML/CSS/JSS
   * Navigation Overview
   * Refactoring
   * Selecting PHP
   * Signature Helper
   * Tooltips
   * Writing PHPDoc
 * Installation
   * Installation
   * Web Extension


DEBUG OVERVIEW



Debugging of PHP code in VS Code allows for inspecting a PHP program, inspecting
actual variables, stack traces, exceptions, breaking and stepping through the
code, debugging PHPUnit tests, and more.


REQUIREMENTS

In order to debug a PHP program, you need PHP (either installed locally or on
your server) together with Xdebug extension.

 * PHP >= 5.6
 * Xdebug extension. Follow the steps on Xdebug.org Install.


LOCAL PHP INSTALLATION

In case there are more PHP installations on the system, see choosing PHP Version
and select the right one.

To verify your PHP and Xdebug are installed correctly:

 * Open a .php file in VS Code
 * Open the OUTPUT view, tab PHP.



If PHP with Xdebug is installed correctly, you will see

Found PHP, version x.y.z, Xdebug: x.y.z.


PHP.INI CONFIGURATION

Xdebug needs to be set in php.ini file that corresponds to your PHP
installation.

 * On Windows it is located next to your php.exe.
 * On Linux/Mac, there is usually a separate xdebug.ini file (usually something
   like /etc/php/8.0/cli/xdebug.ini).

Edit the .ini file, and ensure there are the following directives (Note, the
directives are different for Xdebug versions 2 and 3):

; Xdebug 3
zend_extension = "<path to the xdebug library>" ; "...\xdebug.dll" or ".../xdebug.so"
xdebug.mode = debug
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9003
xdebug.start_with_request = trigger

; Xdebug 2
zend_extension = "<path to the xdebug library>" ; "...\xdebug.dll" or ".../xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_mode = req


SERVER PHP INSTALLATION

> This applies to the situation when PHP is not running on your local system but
> it's on a Cloud, Web Host, Docker, Xampp, etc.

In case php itself is not running on your local system, consult the installation
of PHP+Xdebug with the specific server host.

You can then take advantage of DBGP Proxy to allow multiple users to debug the
same site safely.


LAUNCHING DEBUG IN VSCODE

Launch debugging in Visual Studio Code to either run the program and debug, or
to listen for incoming Xdebug connections and debug. PHP debugging can be
initiated in several ways, with or without VS Code Workspace, with or without
the configured launch.json.


WITH LAUNCH.JSON

> The file .vscode/launch.json is a configuration file within your VS Code
> Folder or Workspace.

 1. Open Folder or Open Workspace in VS Code. This allows for specifying more
    detailed debug launch configurations.
 2. Navigate to Run and Debug view, and click create a launch.json or the
    configuration gear:
 3. See launch.json for the initialization and description of the PHP launch
    profiles.


NO LAUNCH.JSON, JUST DEBUG

Debugging can be started without any configuration. This is recommended if you
just need to attach to an existing Web Server (with Xdebug configured) or to
quickly run and debug a PHP script.

 1. Open a .php file in VS Code (File / Open File).
 2. Press F5 or Open Command Palette (F1) and choose one of the following:

 * Listen for Xdebug starts debugging and waits for an incoming Xdebug
   connection.
 * Launch current script in console runs and debugs the currently opened PHP
   document as a console PHP program.
 * Launch built-in server starts PHP development server within your opened
   folder, checks for the debugging capabilities, and starts listening for the
   Xdebug connections.


FEATURES

The debugging features are the following:

 * Stepping by line, step in, step out.
 * Placing breakpoints, conditional breakpoints, break on hit count.
 * Logging breakpoint hit into 'Debug console'.
 * Breaking on exceptions, warnings, and errors.
 * Specifying non-user files (exceptions won't break debugging, stepping
   through).
 * Watch tool tips.
 * Listing locals and superglobals.
 * Editing variable or property value, handling long string values efficiently.
 * Long arrays watch efficiently.
 * Debug watch expands objects and arrays.
 * Evaluating code in 'Debug console'.
 * Debug launch profiles.
 * Built-in web development server.
 * Debugging of 'PHP Unit' test cases.


DEBUG ADORNMENTS

When stepping through the code, the editor will display values of variables and
expressions corresponding to the current statement. Values are also shown for
the enclosing scopes such as loop control variables, switch expression, and
function parameters.

This feature can be enabled or disabled using VS Code Setting
"debug.inlineValues".




START DEBUG AND STOP ON ENTRY

Open command palette and run Start Debugging and Stop on Entry (aka Step Into).
The command launches debugging and breaks on the first statement.


TROUBLESHOOTING

These are steps that should help to diagnose and solve common problems with
debugging PHP:

 * Running the following command should display no warnings, and an Xdebug
   notice:
   
   php --version
   
   PHP 8.0.3 (cli) Copyright (c) The PHP Group
   Zend Engine v4.0.3, Copyright (c) Zend Technologies
     with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

 * The port number specified in Xdebug .ini configuration should be 9000 or
   9003, or it should match the "port" specified in the Launch Profiles.

 * Firewall must be properly set up to allow communication through the Xdebug
   port.

 * Append the following query parameter when opening the debugged PHP Web Site:
   
   ?XDEBUG_SESSION_START=1
   
   For example: http://localhost/?XDEBUG_SESSION_START=1

 * In case the VS Code is behind a proxy, see
   https://code.visualstudio.com/docs/setup/network for additional settings.


SEE ALSO

 * Xdebug.org
 * Installing Xdebug on Mac
 * Launch Configurations
 * VS Code Network Settings (Proxy)

In this article:
 * Requirements
   * Local PHP Installation
   * php.ini Configuration
   * Server PHP Installation
 * Launching Debug in VSCode
   * With launch.json
   * No launch.json, Just Debug
 * Features
   * Debug Adornments
   * Start Debug and Stop on Entry
 * Troubleshooting
 * See Also

Back to top

GET NEWSLETTER



CONNECT WITH US



SITE MAP

 * Home
 * Features
 * Download
 * Blog
 * Documentation
 * Support
 * Purchase

COMPANY

 * About Us
 * Partners
 * Jobs

CONTACT US

 * info@devsense.com
 * Support Forum

EnglishEspañol日本 (日本語)Português

--------------------------------------------------------------------------------

© 2009 — 2022 DEVSENSE s.r.o. All rights reserved. Developed with PHP Tools for
Visual Studio