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.

<?php
  echo $_SERVER["DOCUMENT_ROOT"]
?> 

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 http://your-domain.co.uk/docroot.php (while replacing your-domain.co.uk/docroot.php with your actual domain and the name of the file you created).

The output should look something like this:

/customers/homepages/xx/dxxxxxxxxxxx/htdocs