What is the best practice for determining the path of the index.php file in PHP?

When determining the path of the index.php file in PHP, it is best practice to use the $_SERVER['DOCUMENT_ROOT'] variable to get the root directory of the server. This will provide a reliable way to construct the path to the index.php file regardless of the server configuration.

$index_path = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
echo $index_path;