php / php/php-src

`DOCUMENT_ROOT` from environment in cli is not propagated to $_SERVER['DOCUMENT_ROOT']

Open
#20,749 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.