Setup Visual Studio Code + Laradock + xDebug

Viusal Studio Code

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform — Linux, macOS and Windows.

Laradock

Laradock is a full PHP development environment for Docker.

xDebug

xDebug is an extension for PHP to assist with debugging and development.

Edit the .env file inside the Laradock folder

  • nano .env
  • Find WORKSPACE_INSTALL_XDEBUG and replace it’s value by true
  • Find PHP_FPM_INSTALL_XDEBUG and replace it’s value by true

Edit the xDebug configuration files

  • nano workspace/xdebug.ini
  • nano php-fpm/xdebug.ini
  • Replace the contents of both files with:
xdebug.remote_host=host.docker.internal
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.idekey=VSCODE
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.cli_color=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="~/xdebug/vscode/tmp/profiling"
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1

Rebuild the workspace and php-fpm containers and restart them

  • docker-compose build workspace php-fpm
  • docker-compose up -d workspace php-fpm
  • docker-compose restart workspace php-fpm

Activate xDebug in Visual Studio Code

  • In the Visual Studio Code menu, click Run and then Add Configuration
  • Add the configuration below:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true,
"pathMappings": {
"/var/www": "${workspaceRoot}",
},
"ignore": [
"**/vendor/**/*.php"
]
}

Start/Stop xDebug

By installing xDebug, you are enabling it to run on startup by default.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store