`DOCUMENT_ROOT` from environment in cli is not propagated to $_SERVER['DOCUMENT_ROOT']
Open
Nobody has claimed this yet.
Feature
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.2k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
DOCUMENT_ROOT=/test php -r 'var_dump($_SERVER["DOCUMENT_ROOT"]);'
Resulted in this output:
string(0) ""
But I expected this output instead:
string(5) "/test"
with a file the out is the same
I think the culprit is https://github.com/php/php-src/blob/42f994cd05da353c93cd65775026859f664289a3/sapi/cli/php_cli.c#L344 as the only mention of DOCUMENT_ROOT for php-cli
PHP Version
PHP 8.4.15 (cli) (built: Nov 20 2025 19:00:52) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.15, Copyright (c) Zend Technologies
with Zend OPcache v8.4.15, Copyright (c), by Zend Technologies
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in sapi/cli/php_cli.c at the DOCUMENT_ROOT handling identified in the issue, and reproduce the command-line example with and without a file. Trace how the environment value reaches $_SERVER; done means PHP CLI exposes /test as $_SERVER['DOCUMENT_ROOT'] in both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100