Yes, the only place that "DocumentRoot" is allowed by Apache to be specified is within the global perspective, or within the <VirtualHost> directive's.  (http://httpd.apache.org/).  Global variables like PHP_SELF and DOCUMENT_ROOT are taken directly from the server environment.

I'm not really sure what to suggest here that would work for you, though, as a matter of minor opinion I'd suggest finding a host that doesn't make you mess with .htaccess files for subdomains. Most hosts I know of, have some sort of web based control panel using Webmin, CPanel, Plesk or a custom made one.

You might be able to create an include file you can include() into any files you use, which would have your own 'document root' variable of sorts ($DOC_ROOT = $_SERVER['DOCUMENT_ROOT']."/subdir/";) and/or modify the output of PHP_SELF ($DOC_SELF = $_SERVER['PHP_SELF']; trim("something", $DOCSELF);)  I'm basically pulling at straws though.  If you are interested in modifying PHP variables and code, I'd suggest looking at PHP's website and/or other forums or mailing lists better suited to PHP.

Hope that helps some...

  - Tony




Kurt Granroth wrote:
The more I research this, the more it looks like I would have to reset the DocumentRoot dynamically... and so far, that doesn't seem possible.  I've tried the following all of the following directives in my .htaccess file (one at a time):

php_value doc_root /var/www/domain.com/sub
php_value user_dir domain.com/sub
DocumentRoot /var/www/domain.com/sub
<Directory /var/www/domain.com/sub>
  DocumentRoot /var/www/domain.com/sub
</Directory>
<Location />
  DocumentRoot /var/www/domain.com/sub
</Location>
<IfModule mod_userdir.c>
  UserDir domain.com/sub
</IfModule>

The PHP ones are ignored.  All the rest give Internal Server errors.  It seems that PHP used to allow setting doc_root and user_dir in .htaccess but that was a bug and was fixed years ago.  Alas.

It's looking like the only way to set the DocumentRoot or UserDir is to do so in the system level httpd.conf.  Am I missing anything, here?

On Jan 15, 2006, at 8:07 PM, John Seth wrote:

If I am writing my own code correctly, $_SERVER['PHP_SELF'] should return the full path of the script and filename from the document root of the website.  If your host has your subdomain set up right, you should be able to issue: "echo $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF']" in a php script and have it return the complete path of the file via the filesystem... take out the "DOCUMENT_ROOT" and you should be left with the path the webserver uses to the script.  The above  example is what I use to include files not in the same directory, minus the php_self obviously.

  However, in cases where I submit a form back onto itself I use $_SERVER['PHP_SELF'] all the time.  Hence my questioning if you know what the server is using for DOCUMENT_ROOT.  If it thinks the document root is "/var/www/domain.com/" and the PHP_SELF refers to "/sub/form.php", then php_self will not return what you expect, nor want it to.

  I would suggest taking a look at: http://us3.php.net/reserved.variables  for more help.

Hope that helps,


   Tony




Kurt Granroth wrote:
Actually, I should have specified that the PHP scripts are all 3rd party ones.  If they are scripts that I wrote, then there are always ways around it.  But the 3rd party ones invariably do 'dirname' on PHP_SELF (or something very similar).  That's why I want to know a way around that at a higher-level.  Maybe some php.ini setting or somesuch.

On Jan 15, 2006, at 5:07 PM, alex@crackpot.org wrote:

Try a test script like this : 'var_dump($_SERVER);'.  This will show you all the
variables provided by the web server (like DOCUMENT_ROOT, PHP_SELF, etc.)  There
may be one which has what you want.  Maybe PATH_TRANSLATED?

alex

Quoting Kurt Granroth <plug-discuss@granroth.org>:

This isn't directly Linux related but since I know there are a lot of
PHP folks on this list, I thought I'd ask here.

I have multiple domain and multiple subdomain support with my web
hosting enabled mostly by using mod_rewrite.  The end result is that
I can define my domains and subdomains by just creating the proper
directory structure.

For instance, say I have "sub.domain.com", "other.domain.com", and
"cool.com".  I would simply create following directory structure:

$DOCUMENT_ROOT/domain.com/sub/
$DOCUMENT_ROOT/domain.com/other/
$DOCUMENT_ROOT/cool.com/

So far, so good.  That all works just as expected.  Now say, though,
that I have a PHP file 'index.php' in the directory 'domain.com/sub'
that looks like so:

<?php echo $_SERVER["PHP_SELF"] ?>

I then execute the script using "http://sub.domain.com/index.php".
The result:

/domain.com/sub/index.php

This is technically accurate... but not at all what I want.  Why?
Because typically, PHP code uses the dirname() of this to find other
relative scripts.  If you do that, though, then the constructed URL
will look like so:

http://sub.domain.com/domain.com/sub/someother.php

instead of

http://sub.domain.com/someother.php

So it seems that I somehow have to "fool" PHP into thinking that
PHP_SELF (and SCRIPT_NAME and SCRIPT_FILENAME) is "/index.php"
instead of "/domain.com/sub/index.php"

Is that even possible?  If so, how.  If not, is there any way around
this at all?

Thanks!
Kurt
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change  you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss



---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change  you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss



---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change  you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change  you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change  you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss