Welcome! Log In Create A New Profile

Advanced

[PHP] Difficulty navigating symlinks

Posted by Seth Foss 
Seth Foss
[PHP] Difficulty navigating symlinks
October 22, 2008 06:00PM
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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Robert Cummings
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 06:25PM
On Wed, 2008-10-22 at 11:59 -0400, 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?

Why not use CVS or SVN and just checkout the code? Sure you have it in
multiple places that way, but it's a cinch to deploy and allows rollback
to specific versions on any given tree.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 06:55PM
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 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
Seth Foss
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 07:15PM
Robert Cummings wrote:
> On Wed, 2008-10-22 at 11:59 -0400, 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?
>>
>
> Why not use CVS or SVN and just checkout the code? Sure you have it in
> multiple places that way, but it's a cinch to deploy and allows rollback
> to specific versions on any given tree.
>
> Cheers,
> Rob.
>
Thanks for the advice, Rob. I actually do have CVS and have been using
it the way you describe. However, the sheer quantity of websites is
beginning to overwhelm our disk space, especially when you consider that
everything but the configuration is identical, and we do almost no
modification to 95% of the code.

Anyway, if it isn't possible, then that's fine. I'm just trying to use
our resources as efficiently as possible.

Does anyone have any other ideas?

Seth


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Seth Foss
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 07:20PM
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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Robert Cummings
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 07:35PM
On Wed, 2008-10-22 at 13:16 -0400, Seth Foss wrote:
> Robert Cummings wrote:
> > On Wed, 2008-10-22 at 11:59 -0400, 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?
> >>
> >
> > Why not use CVS or SVN and just checkout the code? Sure you have it in
> > multiple places that way, but it's a cinch to deploy and allows rollback
> > to specific versions on any given tree.
> >
> > Cheers,
> > Rob.
> >
> Thanks for the advice, Rob. I actually do have CVS and have been using
> it the way you describe. However, the sheer quantity of websites is
> beginning to overwhelm our disk space, especially when you consider that
> everything but the configuration is identical, and we do almost no
> modification to 95% of the code.
>
> Anyway, if it isn't possible, then that's fine. I'm just trying to use
> our resources as efficiently as possible.
>
> Does anyone have any other ideas?

What I do in almost all my projects is declare in a config someplace the
absolute path to the web tree on the filesystem.... something like:

$GLOBALS['interJinn']['pageRoot'] = '/path/to/website/pages/';

Then in weird cases like this I could use that to get the include path
since I know where my site is. In fact, you can even auto set the root
path using something like:

$GLOBALS['interJinn']['pageRoot'] = dirname( __FILE__ ).'/';

Then you don't even need to actually set it when you move your site
around as long as the config is in root. If the config isn't in the root
directory then just chop off directories from the end until you have the
root location.


HTH,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 08:15PM
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

--
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
Yeti
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 08:15PM
If you are in control of you DNS records you could CNAME [1] the sites
to the same address, where a PHP script or RewriteRule [2] loads the
specific configuration by checking the requested URI. Since you got
them on the same server anyways this would not cost any performance.

[1] http://www.zytrax.com/books/dns/ch8/cname.html
[2] http://marc.info/?l=php-general&m=122383066714789&w=2

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Stut
Re: [PHP] Difficulty navigating symlinks
October 22, 2008 08:30PM
On 22 Oct 2008, at 18:16, Seth Foss wrote:
> Robert Cummings wrote:
>> On Wed, 2008-10-22 at 11:59 -0400, 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?
>>>
>>
>> Why not use CVS or SVN and just checkout the code? Sure you have it
>> in
>> multiple places that way, but it's a cinch to deploy and allows
>> rollback
>> to specific versions on any given tree.
>>
>> Cheers,
>> Rob.
>>
> Thanks for the advice, Rob. I actually do have CVS and have been
> using it the way you describe. However, the sheer quantity of
> websites is beginning to overwhelm our disk space, especially when
> you consider that everything but the configuration is identical, and
> we do almost no modification to 95% of the code.
>
> Anyway, if it isn't possible, then that's fine. I'm just trying to
> use our resources as efficiently as possible.
>
> Does anyone have any other ideas?

Check $_SERVER - there's almost certainly a var in there that can help
you get the right absolute path. $_SERVER['DOCUMENT_ROOT'] springs to
mind but whether it's right depends on how your web server is
configured. Create a script with just the following code to see what's
there...

<pre><?php print_r($_SERVER); ?></pre>

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Shawn McKenzie
[PHP] Re: Difficulty navigating symlinks
October 22, 2008 08:45PM
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
Haven't read the entire thread, but you might also look at
http://php.net/manual/en/function.realpath.php

--
Thanks!
-Shawn
http://www.spidean.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Robert Cummings
Re: [PHP] Re: Difficulty navigating symlinks
October 22, 2008 10:05PM
On Wed, 2008-10-22 at 13:43 -0500, Shawn McKenzie 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
> Haven't read the entire thread, but you might also look at
> http://php.net/manual/en/function.realpath.php

realpath() won't help since it will just controbute the same problem...
specifically he'll get the path were the page really exists instead of
the sym'd path which is what he wants.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Boyd, Todd M.
RE: [PHP] Re: Difficulty navigating symlinks
October 22, 2008 11:50PM
> -----Original Message-----
> From: Robert Cummings [mailto:[email protected]]
> Sent: Wednesday, October 22, 2008 3:02 PM
> To: Shawn McKenzie
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Re: Difficulty navigating symlinks
>
> On Wed, 2008-10-22 at 13:43 -0500, Shawn McKenzie 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
> > Haven't read the entire thread, but you might also look at
> > http://php.net/manual/en/function.realpath.php
>
> realpath() won't help since it will just controbute the same
problem...
> specifically he'll get the path were the page really exists instead of
> the sym'd path which is what he wants.

From www.php.net/realpath :

realpath() expands all symbolic links and resolves references to '/./',
'/../' and extra '/' characters in the input path . and return the
canonicalized absolute pathname.

Sounds like it'll work.


Todd Boyd
Web Programmer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Stut
Re: [PHP] Re: Difficulty navigating symlinks
October 23, 2008 12:30AM
On 22 Oct 2008, at 22:45, Boyd, Todd M. wrote:
>>> Haven't read the entire thread, but you might also look at
>>> http://php.net/manual/en/function.realpath.php
>>
>> realpath() won't help since it will just controbute the same
> problem...
>> specifically he'll get the path were the page really exists instead
>> of
>> the sym'd path which is what he wants.
>
> From www.php.net/realpath :
>
> realpath() expands all symbolic links and resolves references to
> '/./',
> '/../' and extra '/' characters in the input path . and return the
> canonicalized absolute pathname.
>
> Sounds like it'll work.

Not even a little bit. The OP needs the directory the symlink lives
in, not the one it points to. As your snippet of the manual says
realpath expands all symbolic links which means it will give the full
path to the directory the symlink points to. Not what's needed.

After you've admitted to not reading the question you might find it
beneficial to go back and do that before arguing that your suggestion
will work.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Seth Foss
Re: [PHP] Difficulty navigating symlinks
October 23, 2008 03:45PM
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.

Seth

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Robert Cummings
Re: [PHP] Difficulty navigating symlinks
October 23, 2008 05:45PM
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.
--
http://www.interjinn.com
Application and Templating Framework for PHP


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Difficulty navigating symlinks
October 23, 2008 07:10PM
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
Seth Foss
Re: [PHP] Difficulty navigating symlinks
October 23, 2008 07:30PM
Jim Lucas wrote:
> 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
>
>
I am ashamed to say that so much have my php coding experience has been
the modification of third-party apps that I never even knew the $_SERVER
variable existed. Even if I had, I probably would have assumed that it
would have given me the app path instead of the website path.

Tried it using Stut's snippet, and it works (not that they should be
related, but just figured I'd mention that it works whether i added the
include path to my VHOST or not).

Two great solutions! I think I'll implement DOCUMENT_ROOT, since that
will require no extra configuration when adding a new site. I can't
imagine a better solution other than tweaking a configuration option to
get '..' to work the way I wanted it too, but from the apache
documentation I saw, it sounds like that would be an apache feature
request, if anything.

Thanks Jim and Stut for your help, and everyone else for their input.
Seth

I

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login