title: PHP Including a File 2 directories back
body: <p>Here is my situation.  I have a <strong>config.php</strong> file that I would like to share between all of my folders.  It is located in my <strong>root: includes/config.php</strong>.</p>
  
  <p>I am in my <em>admin</em> folder and am trying to include that config file. </p>
  
  <pre><code>// Does not work
  require_once "../../includes/config.php";
  
  // This will kind-of-work.. see below
  require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/config.php";
  </code></pre>
  
  <p>The problem with the second line is that I have 3 different environments.  Localhost, Development, and Production.</p>
  
  <p>I define those environments and all the settings in config.php.  If I am on production, then that second line will work perfect.  But on my development and localhost environments.. the files are not in the root directory, they are in a subfolder.. so the only way for that to work would be:</p>
  
  <pre><code>require_once $_SERVER['DOCUMENT_ROOT'] . "/sub_folder/includes/config.php";
  </code></pre>
  
  <p>Well, I have a PATH constant in my config.php file depending on the environment, but I can't access it because I am trying to include that file! </p>
  
  <p>So I'm not sure the best way to approach this.. I hope this made sense.</p>
  
  <p>Any help is appreciated!</p>