title: How to set root folder for PHP include files
body: <p>I've spent days researching the internet and I can't find the answer that I will understand and are able to implement. </p>
  
  <p>I've got the website in which I want to use <code>include_once</code> files and be able to view the website properly in both localhost and the actual server. </p>
  
  <p>I've used <code>$_SERVER['DOCUMENT_ROOT']</code> before but it doesn't work on the localhost so it is hard for me to update and do the changes to the website. </p>
  
  <p>What I want to do is to create some sort of config.php file in which I can tell it that the root folder is either called <code>htdocs</code> or <code>public_html</code> and to "start" looking for files from there.</p>
  
  <p>Or is there any other way I can get include paths to work?</p>
  
  <p>I've seen replies with e.g. <code>dirname(__FILE__)</code>, <code>__DIR__</code>, etc. but they never explained how it would work, where to write it in the code, etc. I'm a bit sick and tired of finding part of the answer and then running around in circles just try and "fill in" the gaps. I'm not a PHP expert, just trying to make my life a bit easier by using it.</p>