| 3:31 pm on May 8, 2008 (gmt 0)|
Is the file actually stored in /Users/mdeclair/Sites/test ? or is it rewritten / served from somewhere else? I am thinking you might need to switch to PATH_TRANSLATED rather than DOCUMENT_ROOT.
| 3:47 pm on May 8, 2008 (gmt 0)|
I would rather have my PHP environment behave a closely to my clients environment as possible. Cuts down on the bugs.
| 3:55 pm on May 8, 2008 (gmt 0)|
Which is correct will depend on where the script is actually running though, correct?
If the script is running in /Users/mdeclair/Sites/test/ then DOCUMENT_ROOT is correct, but if the script is running in /Users/mdeclaire/Sites/ directly, then you will need to use PATH_TRANSLATED (or SCRIPT_FILENAME depending on Apache version and AcceptPathInfo setting)... It was the reason I was asking where the php file was actually located anyway.
| 4:08 pm on May 8, 2008 (gmt 0)|
Maybe I misunderstood.
I've got the dir: /Users/mdeclair/Sites/, and within it, many directories, one per project. So:
I'd like to use http://coolsite.matt.dev, and have it resolve to /Users/mdeclair/Sites/coolsite.com/index.php, with $_SERVER['DOCUMENT_ROOT'] = /Users/mdeclair/Sites/coolsite.com
| 4:17 pm on May 8, 2008 (gmt 0)|
I understand (I think), but for DOCUMENT_ROOT to = /Users/mdeclair/Sites/coolsite.com the current running script will have to physically be located in /Users/mdeclair/Sites/coolsite.com.
Let me give you a 'for instance'...
If you do not have a physical directory called /Users/mdeclair/Sites/coolsite.com, with the file located within the directory, DOCUMENT_ROOT will return the incorrect location.
IOW If you 'dynamically create' the directories for use, and then rewrite the directory to another location to access the script you will receive the location of the script with DOCUMENT_ROOT, but will receive the 'virtual location' using PATH_TRANSLATED or SCRIPT_FILENAME.
If the script is located at /Users/mdeclair/Sites/awesomesites.php but runs when /User/mdeclair/Sites/awesomesite.com/ is opened, you will receive the incorrect location using DOCUMENT_ROOT, because it gives you the physical server path to the actual location of the current script, not a rewritten or dynamically generated path.
If the script is physically located at /User/mdeclair/Sites/awesomesite.com/index.php then DOCUMENT_ROOT *should* give you the correct path/location. If the script is physically stored in another location on the server, then you will have to use one of the other server variables to return the current 'dynamic' location of the request.
| 4:25 pm on May 8, 2008 (gmt 0)|
The 'short' version is where are you actually storing the file you are testing on your server?
If it is in /User/mdeclair/Sites/ then everything is working correctly. If it is physically stored in /User/mdeclair/Sites/awesomesite.com/ right now, then I will have to think for a minute.
| 10:49 pm on May 8, 2008 (gmt 0)|
I think my situation is your latter explanation.
file location: /Users/mdeclair/Sites/awesomesite/test.php
script: <?php echo $_SERVER['DOCUMENT_ROOT']; ?>
current output: /Users/mdeclair/Sites
desired output: /Users/mdeclair/Sites/awesomesite
| 3:00 pm on May 19, 2008 (gmt 0)|
The problem here is that when using mod_vhost_alias to create dynamic domains, the internal Apache DocumentRoot/DOCUMENT_ROOT value for that VirtualHost/Domain gets set to the default httpd.conf value [whatever it may be]. There is no way to change or fix this behavior. Only script workarounds.
| 3:13 pm on May 19, 2008 (gmt 0)|
Thanks for you help. I've since just reverted to using VirtualHosts for my subdomains.
| 3:25 pm on May 19, 2008 (gmt 0)|
Maybe "SCRIPT_FILENAME" will work for you.
$parts = explode( '/', $_SERVER['SCRIPT_FILENAME'] );
array_pop( $parts );
$path = implode( '/', $parts );
| 10:44 pm on May 19, 2008 (gmt 0)|
Thank you, but I do not want to change the script.
I would want to have the environment mimic the end production environment, so that deployment would not involve any changes to the script.