PHP error guide
Xdebug trace file could not be opened: meaning and fix
Error summary
Set output_dir to an existing path writable by the active SAPI user. Function tracing cannot create its output file at xdebug.output_dir.
What it means
Set output_dir to an existing path writable by the active SAPI user. Function tracing cannot create its output file at xdebug.output_dir.
What the error means
This message means that function tracing cannot create its output file at xdebug.output_dir. The exact signature distinguishes xdebug trace file could not be opened from a generic application failure.
Why PHP produces it
The engine or service reports “Xdebug trace file could not be opened” because its required precondition was not met. Set output_dir to an existing path writable by the active SAPI user.
PHP version notes
The xdebug trace file could not be opened wording here is based on Xdebug 3.x except the nesting-level legacy page; punctuation and exception class names can differ on older branches or vendor builds.
Most common causes
- The immediate input or configuration reaches the specific condition: function tracing cannot create its output file at xdebug.output_dir
- The code path assumes the prerequisite for xdebug trace file could not be opened has already been satisfied.
- For xdebug trace file could not be opened, development and production differ in version, extension, permissions, paths, or service configuration.
- An earlier operation returned an unchecked value that is consumed by the line reporting xdebug trace file could not be opened.
Minimal examples
BAD — reproduces the problem
xdebug.output_dir=/traces
FIXED — safer pattern
xdebug.output_dir=/var/tmp/xdebug-traces
Step-by-step diagnosis
- Copy the complete “Xdebug: [Tracing] File '/traces/trace.123.xt' could not be opened.” text and retain the first application stack frame.
- Reproduce xdebug trace file could not be opened in the same SAPI and environment listed for this page.
- Before changing xdebug trace file could not be opened, inspect the preceding value or directive and verify its type, path, version, and permissions.
- Apply the narrow correction—set output_dir to an existing path writable by the active SAPI user—then repeat the original request once.
Fixes
Correct the failing prerequisite
Set output_dir to an existing path writable by the active SAPI user
xdebug.output_dir=/var/tmp/xdebug-traces
Fail explicitly at the boundary
Validate the condition before the operation that emits xdebug trace file could not be opened, and log a safe diagnostic without credentials or full production paths.
Common mistakes when fixing it
- Suppressing xdebug trace file could not be opened instead of correcting its upstream condition.
- Testing xdebug trace file could not be opened only with the CLI binary when the failing request runs under FPM or Apache.
- Changing a global setting for xdebug trace file could not be opened before confirming the site-specific effective configuration.
How to prevent it
- Add a focused test that exercises the boundary responsible for xdebug trace file could not be opened.
- Keep runtime versions, extensions, configuration, and deploy artifacts affecting xdebug trace file could not be opened reproducible.
- Validate external data and service return values before they can trigger xdebug trace file could not be opened.
Web server / environment notes
fpm, cli, docker, linux. The failure occurs where function tracing cannot create its output file at xdebug.output_dir
Tags: fpm,cli,docker,linux