Debugging PHP with Xdebug

Dumping variables with var_dump() only gets you so far. Xdebug transforms your development workflow by enabling interactive debugging, call stack traces and profiling.

Installation

On Ubuntu, install Xdebug via PECL or your package manager. Then enable it in your php.ini:

sudo apt install php-xdebug ; in php.ini zend_extension=xdebug.so xdebug.mode=debug xdebug.start_with_request=yes xdebug.client_host=127.0.0.1 xdebug.client_port=9003

Restart your web server or PHP-FPM after installation.

Using an IDE

Most editors support Xdebug. In VS Code, install the PHP Debug extension and add a launch configuration. When you trigger a request, VS Code will break at your defined breakpoints.

Remote CLI debugging

You can also debug CLI scripts by exporting XDEBUG_SESSION=1 or by starting the script with the environment variable:

XDEBUG_SESSION=1 php artisan migrate

Interactive debugging helps you understand complex logic, inspect variable state and step through execution line by line.