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’].


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



Will Return

 example /home/yourSite/public_html 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.