XDebug Debugging
Professional PHP debugging out of the box
Every DAMP project comes with XDebug pre-configured and ready to use. Set breakpoints, inspect variables, and step through your code like a pro - all from VS Code.
Zero Configuration Required
XDebug is installed and configured automatically in every project. Just press F5 and start debugging immediately!
Quick Start
Debug your PHP code in three simple steps:
Open Project in DevContainer
Open your project folder in VS Code and reopen in container.
Set Breakpoints
Click in the gutter next to any line number to add a breakpoint (red dot).
Press F5
Start debugging! VS Code will stop at your breakpoints automatically.
Features
Pre-Configured
XDebug installed and configured in every new project
VS Code Integration
Debug panel, breakpoints, and step controls built-in
Variable Inspection
View and modify variables during execution
Call Stack
Navigate through function calls and trace execution
Pre-Configured Setup
XDebug Configuration
Every project includes .devcontainer/xdebug.ini:
[XDEBUG]
xdebug.mode = develop,debug,trace,coverage,profile
xdebug.start_with_request = trigger
xdebug.client_port = 9003What This Means
- develop,debug - Full debugging capabilities enabled
- trigger - Debugging starts only when triggered (via browser extension or URL parameter)
- 9003 - Standard XDebug 3.x port
Why Trigger Mode?
Trigger mode means XDebug only activates when you explicitly request it, preventing unnecessary overhead. Use a browser extension or add ?XDEBUG_TRIGGER=1 to URLs to start debugging.
VS Code Launch Configuration
Included in .vscode/launch.json:
{
"type": "php",
"request": "launch",
"name": "Listen for Xdebug",
"port": 9003,
"pathMappings": {
"/workspace/yourproject": "${workspaceFolder}"
}
}Debugging Workflows
Basic Debugging
- Set Breakpoint - Click next to line number
- Press F5 - Start debug session
- Navigate Code
- Access your site in browser
- XDebug triggers on breakpoint
- Use debug toolbar to step through
Trigger Mode
XDebug is configured with start_with_request = trigger, which means debugging only starts when triggered - giving you full control over when to debug.
Using Browser Extension
The easiest way to trigger XDebug is with a browser extension:
Chrome/Edge:
- Install Xdebug Helper
- Click the extension icon → Enable "Debug"
- Green bug icon means debugging is active
- Browse your site - breakpoints will trigger
Firefox:
- Install Xdebug Helper
- Same workflow as Chrome version
Without Extension:
Add ?XDEBUG_TRIGGER=1 to any URL:
https://myapp.local/?XDEBUG_TRIGGER=1Conditional Breakpoints
Set breakpoints that only trigger when conditions are met:
- Right-click on breakpoint or gutter
- Select "Add Conditional Breakpoint"
- Enter condition (e.g.,
$count > 10) - Breakpoint only triggers when condition is true
Pro Tip: Logpoints
Instead of adding echo or var_dump, use logpoints! Right-click → "Add Logpoint" to log messages without modifying code.
Advanced Features
Inspecting Variables
View Current State:
- Hover over variables in code
- Expand in Variables panel
- See type, value, and structure
Modify During Debug:
- Right-click variable in panel
- Select "Set Value"
- Change value and continue execution
Watch Expressions
Monitor complex expressions:
// Watch these expressions:
$user->name
count($items)
$total > 100Add in Watch panel to track changes throughout execution.
Exception Breakpoints
Break when exceptions are thrown:
- Open Breakpoints panel
- Click "+ Add Exception Breakpoint"
- Choose exception types
- Debugger stops on exceptions
Laravel Debugging
Artisan Commands
Debug Laravel artisan commands:
{
"name": "Debug Artisan Command",
"type": "php",
"request": "launch",
"program": "/workspace/yourproject/artisan",
"args": ["your:command"],
"cwd": "/workspace/yourproject"
}Queue Workers
Debug queue jobs:
- Set breakpoint in job
handle()method - Start debug session (F5)
- Dispatch job to queue
- Debugger stops at breakpoint
Testing
Debug PHPUnit tests:
- Set breakpoint in test method
- Run test with coverage
- Debugger stops at breakpoint in test
Common Use Cases
🐛 Hunting Bugs
Find that elusive bug causing issues:
// Set breakpoint here
public function calculateTotal($items) {
$total = 0;
foreach ($items as $item) {
$total += $item->price; // Inspect $item here
}
return $total;
}📊 Understanding Flow
Trace execution through complex code:
// Set breakpoints at each step
public function processOrder($order) {
$this->validate($order); // Step 1
$this->charge($order); // Step 2
$this->fulfill($order); // Step 3
$this->notify($order); // Step 4
}🔍 Inspecting Data
See exact values during runtime:
// What does $data actually contain?
public function transform($data) {
// Set breakpoint - inspect $data structure
return $this->mapper->map($data);
}Customization
Modify XDebug Settings
Edit .devcontainer/xdebug.ini for custom configuration:
[XDEBUG]
xdebug.mode = develop,debug,trace,coverage,profile
xdebug.start_with_request = trigger
xdebug.client_port = 9003
; Add custom settings:
xdebug.log = /tmp/xdebug.log
xdebug.max_nesting_level = 512Rebuild Container:
After changes, rebuild with Ctrl+Shift+P → "Dev Containers: Rebuild Container"
Remember to Rebuild
XDebug configuration changes require a container rebuild to take effect!
Troubleshooting
Happy Debugging!
XDebug is ready to use in every project - no setup required. Just open in VS Code, press F5, and start debugging like a professional!