php get root path

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some.

You can get root path in php using $_SERVER[‘DOCUMENT_ROOT’].

What is $_SERVER[‘DOCUMENT_ROOT’] ?

The document root directory under which the current script is executing, as defined in the server’s configuration file.

Example

   echo  $_SERVER['DOCUMENT_ROOT'];

Will Return

 example /home/yourSite/public_html