Debugging PHP Applications with Xdebug

var_dump() and error_log() get you surprisingly far, but Xdebug’s real step-through debugger — pausing execution, inspecting variables, stepping line by line — finds bugs that print-statement debugging simply can’t.

zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003

Connecting from Your Editor

VS Code’s PHP Debug extension (or PhpStorm’s built-in debugger) listens on port 9003 by default — set a breakpoint, load the page, and execution pauses right there with the full variable state visible, call stack included.

function calculateTotal(array $items): float {
    $total = 0;
    foreach ($items as $item) {
        $total += $item['price'] * $item['qty']; // set a breakpoint here
    }
    return $total;
}

Xdebug also profiles performance (cachegrind output, viewable in tools like QCacheGrind) — genuinely useful for finding the specific function eating your response time, rather than guessing.