title: How to include file outside document root?
body: <p>What I want do to is to include 'file1.php' from 'domain1' into 'file2.php' on 'domain2'. So what I figured I should do is something like this:</p>
  
  <pre><code>file2.php
  require_once '/var/www/vhosts/domain1/httpdocs/file1.php';
  </code></pre>
  
  <p>But this won't work for reasons I can't truly grasp. So what I did was to add my path to the include path. Something like:</p>
  
  <pre><code>file2.php
  set_include_path(get_include_path() . PATH_SEPARATOR . "/var/www/vhosts/domain1/httpdocs");
  require_once 'file1.php';
  </code></pre>
  
  <p>So can you please give me some hints as of where I'm doing wrong ?</p>
  
  <p>Thanks</p>
  
  <p>UPDATE - Either way I get the following error message:</p>
  
  <pre><code>Fatal error: require() [function.require]: Failed opening required '/var/www/vhosts/domain1/httpdocs/file1.php' (include_path='.:/php/includes:/usr/share/pear/') in /var/www/vhosts/domain2/httpdocs/file2.php on line 4
  </code></pre>
  
  <p>Also I have tried this both with safe_mode On and Off.</p>
  
  <p>UPDATE2: Also I've changed the permissions to 777 on my test file and I've double-checked the paths to the include file in bash.</p>
  
  <p>SOLUTION: I've managed to solve the mystery! My hosting company uses Plesk to manage domains and such. Also the error reporting level in php.ini was not E_ALL. When I set error reporting to E_ALL I got a warning saying:</p>
  
  <pre><code>Warning: require() [function.require]: open_basedir restriction in effect.
  </code></pre>
  
  <p>So I went in /var/www/vhosts/domain2/conf/httpd.include and edited the open_basedir path. Note that this is not a durable solution since this config file is rewritten by plesk each time the domain config is changed. What you should do is edit (or create) the 'vhost.conf' file in the same directory and then run:</p>
  
  <pre><code> /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=DOMAIN.TLD
  </code></pre>
  
  <p>This should reconfigure the settings for your domain but for some strange reason it won't work with open_basedir. I can modify other things like document_root but it won't change open_basedir, but that's another problem :D</p>
  
  <p>SOLUTION FINAL: For those with the same problem here is the final code that worked. I just added this in /var/www/vhosts/domain2/conf/vhost.conf (you can change '/var/www/vhosts' to '/' or anything you like):</p>
  
  <pre><code>    &lt;Directory /var/www/vhosts/DOMAIN.TLD/httpdocs&gt;
      &lt;IfModule mod_php5.c&gt;
              php_admin_flag engine on
              php_admin_flag safe_mode off
              php_admin_value open_basedir "/var/www/vhosts"
      &lt;/IfModule&gt;
              Options -Includes -ExecCGI
      &lt;/Directory&gt;
  </code></pre>
  
  <p>Thank you all guys!</p>