Jared Eitnier
Jared Eitnier

Reputation: 7152

php get document root of server via CLI

Simply, I want to get $_SERVER['DOCUMENT_ROOT'] from the command line using PHP.

The PHP docs state:

You may or may not find any of the following elements in $_SERVER. Note that few, if any, of these will be available (or indeed have any meaning) if running PHP on the command line.

Is there a known alternative to achieve the result? Apologies in advance if this is a duplicate, but I can't find anything on this specific question.

Upvotes: 5

Views: 2370

Answers (1)

Marcio Mazzucato
Marcio Mazzucato

Reputation: 9295

You can use:

$pwd = getenv('PWD');   // Current directory
$home = getenv('HOME'); // Home user directory

You can see more details in this answer.

Upvotes: 1

Related Questions