Robert Cummings wrote:
> On Thu, 2008-10-23 at 09:46 -0400, Seth Foss wrote:
>> Jim Lucas wrote:
>>> Seth Foss wrote:
>>>
>>>> Jim Lucas wrote:
>>>>
>>>>> Seth Foss wrote:
>>>>>
>>>>>
>>>>>> Hi everyone,
>>>>>>
>>>>>> I am trying to run multiple sites on the same server, that have mostly
>>>>>> identical code - a pre-built application.
>>>>>>
>>>>>> Anyway, I would like to save disk space by specifying independent
>>>>>> configuration files for each site, then using symbolic links to access
>>>>>> the rest of the code for the application.
>>>>>>
>>>>>> I have managed to configure apache so one such directory is accessed via
>>>>>> a symlink, which is ok. However, a file within the linked directory
>>>>>> attempts to include the configuration file (../config.php) from the
>>>>>> actual parent directory instead of the directory containing the symlink.
>>>>>>
>>>>>> Is there any way to configure apache or php to trace back the symlink
>>>>>> when using '..', or can that only go one direction?
>>>>>>
>>>>>> Thanks,
>>>>>> Seth
>>>>>>
>>>>>>
>>>>>>
>>>>> You can set the include path for your code to include the parent
>>>>> directory
>>>>> from where the symlink is and then remove the ../ part of the call.
>>>>>
>>>>>
>>>>>
>>>> Jim,
>>>>
>>>> I had considered that, but I plan to have multiple directories following
>>>> symlinks to the same place.
>>>>
>>>> For example,
>>>>
>>>> /var/www/site1 has a config.php and a symlink to var/www/universal/app
>>>> while
>>>> /var/www/site2 has a different config.php and a symlink to
>>>> var/www/universal/app
>>>>
>>>> var/www/universal/app has an index.php with include(../config.php) that
>>>> needs the config from the site that is using it (i.e., sometimes site1,
>>>> sometimes site2)
>>>>
>>>> Does that make sense? Or did I misunderstand your suggestion?
>>>>
>>>> Thanks,
>>>> Seth
>>>>
>>>>
>>>>
>>> You might have miss understood me.
>>>
>>> In your VHOST entries, make an entry on each domain
>>>
>>> <VirtualHost X.X.X.X>
>>> DocumentRoot /path/to/example.com/public_html
>>> ServerName example.com
>>> php_value include_path '/path/to/example.com/public_html
>>> </VirtualHost>
>>>
>>>
>>> Now you have your app symlinked into the public_html dir as such (guessing
>>> here)
>>>
>>> ln -s /path/to/my/app /path/to/example.com/public_html/app
>>>
>>> Now, in the app directory you have index.php that has include
>>> '../config.php';
>>>
>>> Your problem is that the ../config.php reference refers to
>>> /path/to/my/app/../config.php == /path/to/my/
>>> instead of
>>> /path/to/example.com/public_html/app/../config.php
>>>
>>> Correct???
>>>
>>> This is because it is being referenced logically from
>>> /path/to/my/app/index.php
>>>
>>> any symbolically from
>>> /path/to/example.com/public_html/app/index.php
>>>
>>> If that is the case, add the vHOST entry that I talked about above, then
>>> reference the config file as include 'config.php'; and it will then look in
>>> the include_path location(s) for the files and not think of referencing the
>>> current directory that it is in.
>>>
>>> Mind you that you can also enter this information into a .htaccess that is
>>> located in the /path/to/example.com/public_html/ directory. As long as
>>> .htaccess files are allowed.
>>>
>>> I usually have my include_path set to ".:/path/to/example.com/public_html/"
>>> in
>>> my vhosts entry for each domain.
>>>
>>> Hope this helps
>>>
>> I did misunderstand. This approach is working for me. Unfortunately, as
>> I am implementing it, it seems there are more files than I expected that
>> utilize a series of '..'s instead of the absolute path from the config
>> file, and more files than I expected that include the config file
>> themselves.
>>
>> However, these would cause me the same headaches with any of the
>> proposed solutions.
>>
>> Long story short, problem is solved. Setting the include path in VHOST
>> lets me set it uniquely for each site, and then including config.php
>> directly (no ..) uses that include path to grab the appropriate config file.
>>
>> Thanks to everyone for your help, and especially you, Jim, for your
>> elegant solution.
>
> You could probably set a value in the vhost that makes the absolute path
> to the web root available to your script. Personally, I hate to rely on
> anything magical like non-standard include paths :)
>
> Cheers,
> Rob.
You are probably right.
I was thinking, why could the "app" know its home and then also use just
DOCUMENT_ROOT?
I can't imagine a time that DOCUMENT_ROOT would not be correct, even from a
symlinked directory.
/app/index.php
<?php
define('ROOT', $_SERVER['DOCUMENT_ROOT']);
include ROOT . 'config.php';
...
?>
You could also then use this ROOT constant else where in your code when you
need to refer to the website root path, instead of the app path
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php