[Asked this at SU; suggestion there was to repost at SO]
We have PHP programs that use $_SERVER['DOCUMENT_ROOT'] as a path to a place where we can place a private directory (using a unique name) in a safe, known place on server. This directory holds data summaries collected from multiple perhaps thousands of served PHP pages; this summary has no impact on the main functionality of the pages served, and eventually can be ignored or deleted. While it exists, a PHP-based tool can inspect the summary data and provide a report.
This has worked well on a variety of PHP servers, and appears to be "automatically" (?) set according to the PHP Manual documentation:
The document root directory under which the current script
is executing, as defined in the server's configuration file.
$_SERVER['DOCUMENT_ROOT'] is found in your apache
httpd.conf and it can be configured. It's the directory out of which you will serve your documents. By default, all web requests are taken from this directory so it should not be null.
This link gives you quick run-down as to why documentroot is in place: http://httpd.apache.org/docs/2.4/urlmapping.html#documentroot.
I personally don’t see an issue using
$_SERVER['DOCUMENT_ROOT'] for servers which I have full control, but I would be wary using this path reference on shared hosting solution’s due to aliases in the config. In this instance, I would just set the
<?php echo $_SERVER['DOCUMENT_ROOT'];//Real Path $_SERVER['DOCUMENT_ROOT'] = "/new/path/www"; echo $_SERVER['DOCUMENT_ROOT'];//New Path ?>