Skip to content

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

@ivan-u7n

Description

@ivan-u7n

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

if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len)) {
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions