Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 823
Jared Eitnier Avatar asked Nov 12 '22 10:11

Jared Eitnier


1 Answers

You can use:

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

You can see more details in this answer.

like image 189
Marcio Mazzucato Avatar answered Nov 15 '22 11:11

Marcio Mazzucato