$ _ SERVER contains headers that will not be available in the CLI. The web server determines the root of the document. In the CLI you are not using a web server, therefore there is no root document.
You can try to rely on environment variables assuming they are set by your shell.
For example, PWD represents the current directory, and HOME represents the user's home directory.
$pwd = getenv('PWD'); $home = getenv('HOME');
You can also use __FILE__ or __DIR__ magic constants to try to __DIR__ path you are currently on.
source share