Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14580

Re: Getting the website document root portably (Apache, IIS, maybe others) and simply

From crankypuss <crankypuss@nomail.invalid>
Newsgroups comp.lang.php
Subject Re: Getting the website document root portably (Apache, IIS, maybe others) and simply
Date 2014-11-14 02:35 -0700
Organization A noiseless patient Spider
Message-ID <m44icm$7td$1@dont-email.me> (permalink)
References <m42m6j$6vd$1@dont-email.me> <cck8l8F3b8nU1@mid.individual.net>

Show all headers | View raw


On 11/13/2014 10:38 AM, J.O. Aho wrote:
> On 13/11/14 17:28, James Harris wrote:
>> This is a question that has been asked before but there seems no
>> consensus
>> in the answers given out there in internet land so I wonder if folks
>> on this
>> newsgroup can recommend a currently accepted best-practice solution. What
>> should a PHP file do in order to find out the "document root"? I am
>> looking
>> for a solution that is portable across different web servers and OSes
>> and is
>> simple enough to be present verbatim on any page which needs such info.
>
> This depends on the webserver used, which method of how PHP is used
> (mod_php, php-fpm, fastcgi and so on) togehter with the webserver and
> even if you have the DOCUMENT_ROOT, it may not be pointing on the
> directory you think it may be.
>
> You will simply have to figure it out for each webserver and how the php
> is used and hope that the configuration will not be using rewrites to
> lessen the restart of the webservise when hosting a large number of
> sites (then you will have a DOCUMENT_ROOT which includes all the users
> home directories) and then make cases for those options and from phpinfo
> determine which method needs to be used.
>
>

Do note that in some cases (eg godaddy) in addition to "DOCUMENT_ROOT" 
being set, "SUBDOMAIN_DOCUMENT_ROOT" may also be set.

In every case I have seen, one can count on the __FILE__ being set to 
the currently executing file, though that is mostly useful in an 
index.php situation since otherwise __FILE__ might be in some include 
directory or something else that confuses the issue.

And of course I haven't worked with every permutation of invoking 
methodology, so what I'd suggest is [a] find something that works for 
your situation, [b] make it as general as possible without expecting the 
moon, [c] when (not if) you get confused, do something else for a while.

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Getting the website document root portably (Apache, IIS, maybe others) and simply "James Harris" <james.harris.1@gmail.com> - 2014-11-13 16:28 +0000
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "J.O. Aho" <user@example.net> - 2014-11-13 18:38 +0100
    Re: Getting the website document root portably (Apache, IIS, maybe others) and simply Matthew Carter <m@ahungry.com> - 2014-11-13 14:32 -0500
      Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 20:58 +0100
      Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "James Harris" <james.harris.1@gmail.com> - 2014-11-13 20:06 +0000
    Re: Getting the website document root portably (Apache, IIS, maybe others) and simply crankypuss <crankypuss@nomail.invalid> - 2014-11-14 02:35 -0700
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 21:04 +0100
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-11-13 21:53 +0100
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 22:54 +0100

csiph-web