Step-debug PHPUnit tests locally in PhpStorm with Xdebug 3
Configure Xdebug 3, a PHPUnit run/debug configuration, and server path mappings so PhpStorm breakpoints suspend during local test runs.
14 Sept 2026, 07:14 UTC

PhpStorm can suspend a local PHPUnit test at a breakpoint and show variables and the call stack, but only after three things line up: Xdebug 3 is enabled for the CLI PHP interpreter, PhpStorm is listening for debug connections, and the server path mapping translates the path PHP reports into a local file path. This guide covers a Xdebug 3 configuration, a PHPUnit run/debug configuration, and the checks that confirm a breakpoint will hit.
Install and enable Xdebug 3 for CLI
Xdebug 3 replaces the older xdebug.remote_* settings with xdebug.mode. For local PHPUnit debugging, set mode to debug and let PhpStorm initiate the session on demand.
[xdebug]
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=trigger
Place these lines in the php.ini used by the CLI interpreter. Find that file with php --ini | grep 'Loaded Configuration File'. On Debian/Ubuntu the package is typically php-xdebug; install it with root privileges. CLI PHP reads the file on each invocation, so no service restart is required for command-line runs.
# Locate the active php.ini (run in a terminal, normal user)
php --ini | grep 'Loaded Configuration File'
# Confirm Xdebug is loaded (normal user)
php -m | grep xdebug
# Inspect Xdebug 3 settings (normal user)
php --ri xdebug | grep -i 'mode\|client_host\|start_with_request'
Expected output: php -m prints xdebug, and php --ri shows xdebug.mode includes debug. If php -m returns nothing, the extension is not installed or not loaded for the CLI SAPI. With xdebug.start_with_request=trigger, ordinary PHPUnit runs are not slowed unless you add the trigger.
Create the PHPUnit run/debug configuration
In PhpStorm, open Run > Edit Configurations, add PHPUnit, and point it at the project's phpunit.xml. Use the project's PHP interpreter and set the working directory to the project root.
- Test runner: Default configuration file
- Path to phpunit.xml: /path/to/project/phpunit.xml
- PHP interpreter: the interpreter with Xdebug installed
- Working directory: /path/to/project
The configuration tells PhpStorm which bootstrap and test suite to execute; Xdebug handles the connection back to the IDE.
Map server paths so breakpoints resolve
When Xdebug connects, it sends the absolute path of the running script. PhpStorm looks up that path in the Servers table and opens the mapped local file. Without a matching mapping, the breakpoint may never bind, or PhpStorm may ask you to map the file manually.
| Server path (absolute path PHP reports) | Local path (PhpStorm project) |
|---|---|
| /var/www/html/project | /home/user/project |
| /srv/www/project | /Users/name/project |
Open Settings > Languages & Frameworks > PHP > Servers, add a server entry, and add the mapping. Use the exact absolute path PHP reports, not a URL and not a relative path. For CLI runs, associate this server with the CLI interpreter in the PHP settings so PhpStorm knows which mapping table to consult.
Start the listener and run PHPUnit
Click the telephone icon in the toolbar (Run > Start Listening for PHP Debug Connections) before executing the test. Then run the PHPUnit configuration. If the connection succeeds, the Debug tool window opens, PhpStorm suspends at the breakpoint, and you can inspect variables, evaluate expressions, and step through the call stack.
Limits and common mistakes
- Path mappings are per-server entry, not global. A mapping for one project does not apply to another.
- xdebug.remote_enable is ignored in Xdebug 3 and silently replaced by xdebug.mode=debug.
- xdebug.client_host must point to the interface where PhpStorm listens; 127.0.0.1 works for local runs on the same machine.
- Start the PhpStorm listener before running PHPUnit. A session started after the test finishes produces no debug window.
- Do not confuse the Xdebug port (default 9003 in Xdebug 3) with unrelated PhpStorm ports; both ends must match.
- Breakpoints in vendor files suspend only if the path mapping covers the vendor directory.
- Firewall or SELinux can block port 9003, causing silent connection failures.
Rollback
Because this procedure edits php.ini, rollback by restoring a backup of the file or commenting out the xdebug block. CLI PHP processes pick up the change on the next invocation; no service restart is required for CLI, though a web server sharing the same ini may need a reload.
Practical verification
Run php --ri xdebug | grep -i 'mode' and confirm debug appears. Start the PhpStorm listener, place a breakpoint in a test method, run the PHPUnit configuration, and confirm the Debug tool window opens and suspends. If it does not, check the Servers path mapping and confirm xdebug.client_host matches the machine running PhpStorm.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.