Php get server root through CLI

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

PHP docs say:

You may or may not find any of the following elements in $ _SERVER. Please note that when you start PHP on the command line, some of them will be available (or even make any sense).

Is there a known alternative to achieve the result? Sorry in advance if this is a duplicate, but I cannot find anything on this particular issue.

+4
source share
1 answer

You can use:

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

You can see more details in this answer .

0
source

All Articles