Getting the Absolute Path (Document Root) Using a PHP Script

For Web Hosting packages

The following code example shows you how to display the path to the main directory of your webspace using PHP.


To run the PHP script on your website:

  • Create a new file with a text editor and copy the code above into it. Then, save the file with the extension .php, such as docroot.php.
  • Upload the script file to your webspace.
  • Go to the script in your browser by using (while replacing with your actual domain and the name of the file you created).

The output should look something like this: