jpalmer Posted August 28, 2009 Share Posted August 28, 2009 Hello, I'm wondering if anyone knows of a quick way to auto-discover the document root in a PHP script when the script is being executed via the command-line? All the servers the script will be running on will be using Apache 1.x or Apache 2.x and the OS' will be either Windows, Redhat, OS X, or Solaris. Any ideas? The command getenv("DOCROOT") or $_SERVER['DOCUMENT_ROOT'] don't work when executing the script via the command-line. Quote Link to comment Share on other sites More sharing options...
ignace Posted August 28, 2009 Share Posted August 28, 2009 If you are executing from the command-line then use this as a quick fix: defined('__DIR__') or define('__DIR__', dirname(__FILE__));//PHP<5.3.0 chdir(__DIR__); This will change the directory from your php executable to the directory in which your files reside. Quote Link to comment Share on other sites More sharing options...
jpalmer Posted August 28, 2009 Author Share Posted August 28, 2009 This is a great fix! Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.