title: Get Apache Document Root from command line execution (No browser)
body: <p>Not sure if the title is correct, Please edit if you think of a better one.</p>
  
  <p>I have a XMLRPC service that I call from the command line. It's using Zend framework.</p>
  
  <p>the client looks like this:</p>
  
  <p>$server = new Zend_XmlRpc_Client('http://hostname/path/to/xmlrpc.server.php');</p>
  
  <p>The file is located:</p>
  
  <pre><code>/var/www/html/path/to/xmlrpc.server.php
  </code></pre>
  
  <p>I have it hard coded now but wanted to populate the 'path/to/' generically. </p>
  
  <p>I've tried:</p>
  
  <pre><code>function url(){
    $protocol = $_SERVER['HTTPS'] ? "https" : "http";
    return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  }
  
  echo url();
  </code></pre>
  
  <p>Note: None of the $_SERVER options returned what I needed</p>
  
  <p>but executing this from the command line gives me:</p>
  
  <pre><code>http://
  </code></pre>
  
  <p>Also <code>getcwd()</code> give me:</p>
  
  <pre><code> /var/www/html/path/to
  </code></pre>
  
  <p>How can I get:</p>
  
  <pre><code>http://path/to
  </code></pre>
  
  <p>Any thoughts?</p>
  
  <p>The reason I would like this is if the project needs to change directories it should auto configure. Example:</p>
  
  <p>If I move the project here:</p>
  
  <pre><code>/var/www/html/path/to/another/location
  </code></pre>
  
  <p>or here:</p>
  
  <pre><code>/var/www/public_html/path/to/another/location
  </code></pre>
  
  <p>or even here:</p>
  
  <pre><code>/path/to/document/root/path/to/another/location
  </code></pre>
  
  <p>I should get:</p>
  
  <pre><code>http://hostname/path/to/another/location
  </code></pre>
  
  <p>Thanks for any help</p>
  
  <p>UPDATE:</p>
  
  <p>I tried this but still not working as expected:</p>
  
  <pre><code>$hostname = `hostname`;
  echo 'http://'.trim($hostname).'/'.basename(getcwd())."\n";
  </code></pre>