Elentra Platform Technical Documentation
  • Introduction
  • Reporting Issues
    • Security Notices
  • Administrators
    • Server Requirements
    • Application Server
      • Shibboleth Single Sign-on
      • Installing Supervisor
      • Branded API Setup
      • Installing Mailhog
    • Database Server
  • Developers
    • Getting Started
    • Overview
    • Contributions
      • Request for Change
      • Jira and GitHub Details
      • Coding Standards
      • Quickstart Guide
      • Code Review
    • Database
    • Dataviews for Analytics
    • Global Namespace
    • Elentra ACL
    • Authentication Methods
    • Compatibility Matrix
    • Elentra ME Versions
    • Elentra Settings
    • Elentra Deployment
    • Elentra API
    • Elentra JS
    • Feature Configuration
      • Event Resource Integration
      • Microsoft Teams Integration
    • Troubleshooting & Guides
      • New developer features in Elentra ME 1.22
      • Testing With Codeception
        • Unit Testing
          • Unit Testing Best Practises
          • Writing Unit Testable Code
          • PHPUnit Testing for API
          • PHPUnit Json String Compare Function
        • Functional Testing
          • Functional Testing Best Practices
        • Integration Testing
          • Integration Testing Best Practices
      • Upgrading elentra-developer Docker
      • VS Code Setup
      • Using XDebug in VSCode
      • Upgrading PHP
      • Switching Databases
      • Creating a new virtual host
      • Logging In
      • Composer
      • Curriculum Tag Selector
      • Performance Issues
      • Docker
      • Seed Data Generation
      • Fail Fast Programming
      • Advanced Custom Exception Classes
    • Support
  • Upgrade Guides
    • Upgrading to ME v28.0
    • Upgrading to ME 1.27
    • Upgrading to ME 1.26
    • Upgrading to ME 1.25
    • Upgrading to ME 1.24
    • Upgrading to ME 1.23
    • Upgrading to ME 1.22
    • Upgrading to ME 1.21
    • Upgrading to ME 1.20
    • Upgrading to ME 1.19
    • Upgrading to ME 1.18
    • Upgrading to ME 1.17
    • Upgrading to ME 1.16
    • Upgrading to ME 1.15
Powered by GitBook
On this page
  1. Developers
  2. Troubleshooting & Guides

Using XDebug in VSCode

PreviousVS Code SetupNextUpgrading PHP

Last updated 3 years ago

Using XDebug in Visual Studio Code is not difficult, but it's easy to miss one detail that prevents the whole thing from working. Here's a step-by-step tutorial:

  • Install the "PHP Debug" VSCode extension by Felix Becker

  • Go to the debug sidebar by clicking on the icon that looks like this:

  • Click on the gear icon to edit the launch.json configuration file

  • Make sure that in the "Debug PHP" section, the port is set to "9000"

  • Add this section within "Debug PHP":

"pathMappings": {
    "/var/www/vhosts/elentra-1x-me": "${workspaceRoot}",
    "/var/www/vhosts/elentra-1x-api": "${workspaceRoot}/www-root/core/library/vendor/elentrapackages/elentra-1x-api"
}

Note: If you include both repositories in the same workspace, the pathMappings section would instead be:

"pathMappings": {
    "/var/www/vhosts/elentra-1x-me": "${workspaceFolder:elentra-1x-me}",
    "/var/www/vhosts/elentra-1x-api": "${workspaceFolder:elentra-1x-api}"
}
  • You can also tell the debugger not to show errors from any code that is in the vendor folder (i.e. third-party code) by defining an ignore section, also within "Debug PHP":

"ignore": [
    "**/vendor/**/*.php"
],
  • You can change the name of the section from "Debug PHP" to "Debug Elentra ME", which may help if you switch projects

  • Save this file

  • Open a terminal window in your "elentra-developer" Docker container

  • Look at the /etc/php.d/15-xdebug.inifile and check that the xdebug.remote_enable option is set to "true"

That is all the setup you need, so go to VSCode and click the green "run" triangle at the top of the debug sidebar (beside "Debug PHP" or "Debug Elentra ME" if you changed the section name).

The bottom of the VSCode editor should turn orange and a small debug toolbar should appear near the top of the window. On any executable line of PHP code, click to the left of the line numbers and a small red dot should appear. This is a breakpoint, where PHP will stop before executing the line.

I use the XDebug helper extension in Firefox, so I click on the bug icon in my address bar and select "Debug"

Refresh the page, or click on a link, or do anything else that should execute the code where you placed the breakpoint. The VSCode window should bring itself to the front, with your breakpoint line highlighted. Now you can explore the variables in scope, set watches, and navigate through the call stack. Happy debugging!

Sample launch.json file

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: <https://go.microsoft.com/fwlink/?linkid=830387>
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Elentra ME",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/var/www/vhosts/elentra-1x-me": "${workspaceRoot}",           
                "/var/www/vhosts/elentra-1x-api": "${workspaceRoot}/www-root/core/library/vendor/elentrapackages/elentra-1x-api"
            },
            "ignore": [
                "**/vendor/**/*.php"
            ]
        }
    ]
}
Options for the Firefox XDebug helper