Find out the root path on your server in PHP

Find out the root path on your server in PHP

Well just a quick post, I’ve started using a new host recently and i’ve been installing oscommerce. Part of oscommerce’s installation process requires the root address on the server to the files but the host didn’t seem to disclose this information so i found the following line of PHP which does the trick.

1) Create a page i.e. root-test.php

2) Add the following line of code to the page:

Remove the spaces appropriately from around the question marks:

< ? = $_SERVER['DOCUMENT_ROOT']; ? >

3) Upload the file.

4) Then go to the file online i.e. http://www.yourdomain.com/root-test.php

It will then give you the appropriate results i.e.

/home/1234/username/www.yourdomain.co.uk/public_html/

Useful piece of code!

Post to Twitter

About the Author

Neil Walker is the founder of SEO at Just Search Ltd who rank on the 1st page of Google UK for "SEO". He has over 7 years experience and dealt with over 2500 clients SEO over the years. He has only started to proactively blog in the past 4 months by running "SEO Mad" - He hopes you find it interesting.