Find the Server Path Using PHP

There are some instances where you may need to get your absolute server path to get your website to work. I've come across this need many times, including for CMS directory path definitions and .htaccess directory definitions.

If your site is coded using PHP, you can find the server path with PHP of any page on your site by placing the following code at the top of the page :

<!--?php echo $file=$_SERVER['DOCUMENT_ROOT']; ?--> 

This bit of code will spit out something like this ; /www/sites/sitename, where "www" is the root directory of the server, "sites" is the root directory of all of your sites, and "sitename" is the root directory of the current site your're working on. You can use this technique to find the absolute server path of any page of your website.