Hi Everyone,

Recently, I was struggling to set up remote debugging on VS code and I thought my experience can help someone. So here is the steps for so.

  1. Install VS code
  2. Install Xdebug on your system. click here for instructions. Add xdebug config to php.ini files
  3. Install PHP debug on VS code . click here for instructions.
  4. Go to your project folder, create new folder called .vscode
  5. Create launch.json file. This is config file for your debugging. You can update this files with the code given on 5.1.
  6. Add breakpoints to the place you want to visualize the process
  7. Click debug on left sidebar panel
  8. On the left top select option Listen for Debug > Click run and debug

You can follow through the VS code debug option on left navigation menu and select launch.json file for config.

1.1

[This config is written for old version 5.5 PHP version and 2.5.5 Xdebug version]
[xdebug: This config goes to php.ini files]
xdebug.remote_enable=on
[This is specifically for docker, you can use localhost instead of host.docker.internal]
xdebug.remote_host=host.docker.internal
xdebug.remote_connect_back=off
xdebug.remote_autostart=on
xdebug.remote_port=9001

For latest Xdebug config there is no much change in it, it’s just values we need to change above. Please refer to this articles.

5.1 So here comes final steps

{
    // 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": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9001,
            "pathMappings": {
                 "/var/www/html": "${workspaceRoot}/src/public"
            }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9001
        }
    ]
}

If you are getting any error like endpoint not available or breakpoint not available, please check if you need pathmapping. Mostly while using with Docker we need to map docker files to local files.

I hope this helps.

Thanks

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: