Skip to content

XDebug Guide

kxwang edited this page May 15, 2018 · 16 revisions

XDebug allows you to debug PHP inside your IDE. In PortlandOR, the IDE is Visual Studio Code. Setup is required in both the Lando environment and the IDE. Running XDebug will slow down your app server. As a result, it's recommended that you only enabled XDebug for debugging sessions.

Prepare Lando environment

  1. Create a file xdebug.ini under your app root folder (portlandor). Copy the following lines and save the file:
xdebug.remote_host = 10.0.75.1
xdebug.idekey = vscode-xdebug
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_autostart=1
  1. In .lando.yml, add two lines to include the xdebug.ini file created in Step 1. Here is the end result.
services:
  appserver:
    xdebug: true
    config:
      conf: xdebug.ini
  1. Only rebuild the app server in your Lando environment: lando rebuild -s appserver -y
  2. (Optionally) Get your environment ready:
lando composer install
lando db-import DB_FILE_HERE
lando drush cim -y

Prepare Visual Studio Code

  1. Install the extension "PHP Debug".
  2. Follow menu "Debug -> Open Configurations" to open the launch.json file. In the Listen for XDebug section, add "pathMappings" to map /app/ (the source code folder in Lando app server) to your local APP root folder. "log" is optional. When it's set to true, you can see the debug logs for XDebug in VS Code.
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log": true,
            "pathMappings": {
                "/app/": "c:/work/lando/portlandor/",
            }
        }
  1. Follow menu "Debug -> Start Debugging" or press F5, the XDebug server will start listening for incoming connections.
  2. Click at the start of a line in index.php to set a breakpoint.
  3. Load any page on your Lando site and see execution stops at the breakpoint.