Welcome to MobyThreads.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in
All support for the MobyThreads Threaded phpBB MOD can now be found on welsolutions at this forum

virtual hosts and root directory for php

 
   Web Hosting and Web Master Forums (Home) -> Apache RSS
Next:  Apache custom handlers using mod_actions  
Author Message
news75

External


Since: Sep 23, 2004
Posts: 2



(Msg. 1) Posted: Fri Sep 24, 2004 2:48 am
Post subject: virtual hosts and root directory for php
Archived from groups: alt>apache>configuration (more info?)

Hi,
I'm using Apache 1.3.29 on Mac OS X for testing purposes. I achieved to
create some virtual hosts.

But when a file tries to php include() some file that is referred to
like /include/file.txt (include("/include/file.txt")WinkI get errors:

 > Warning: main(/include/file.txt): failed to open stream:
 > No such file or directory in /Users/pofi/Sites/pofi.de/index.html on line 18
 >
 > Warning: main(): Failed opening '/include/file.txt' for
 > inclusion (include_path='.:/usr/lib/php') in /Users/pofi/Sites/pofi.de/index.html
 > on line 18
 >

My virtual hosts config is e.g.

<VirtualHost *>
ServerName test.pofi.de
DocumentRoot /Users/pofi/Sites/pofi.de
</VirtualHost>

Is there another directive to enable these paths? Or do I have to tweak
the php.ini somewhere? Or did I make a mistake in php syntax?

Would be great if someone could help me.

cu Christoph<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: virtual hosts and root directory for php 
Back to top
Login to vote
spam3

External


Since: Jul 01, 2003
Posts: 411



(Msg. 2) Posted: Fri Sep 24, 2004 2:48 am
Post subject: Re: virtual hosts and root directory for php [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Christoph Hörterer wrote:

 > Hi,
 > I'm using Apache 1.3.29 on Mac OS X for testing purposes. I achieved to
 > create some virtual hosts.
 >
 > But when a file tries to php include() some file that is referred to
 > like /include/file.txt (include("/include/file.txt")WinkI get errors:
 >
  >> Warning: main(/include/file.txt): failed to open stream: No such file
  >> or directory in /Users/pofi/Sites/pofi.de/index.html on line 18
  >>
  >> Warning: main(): Failed opening '/include/file.txt' for inclusion
  >> (include_path='.:/usr/lib/php') in
  >> /Users/pofi/Sites/pofi.de/index.html on line 18
  >>
 >
 >
 > My virtual hosts config is e.g.
 >
 > <VirtualHost *>
 > ServerName test.pofi.de
 > DocumentRoot /Users/pofi/Sites/pofi.de
 > </VirtualHost>
 >
 > Is there another directive to enable these paths? Or do I have to tweak
 > the php.ini somewhere? Or did I make a mistake in php syntax?

easiest way...

include dirname(__FILE__).'/include/file.txt';

Where "/include/file.txt" is relative to the file that you are working on.

--
Justin Koivisto - spam.DeleteThis@koivi.com
<a style='text-decoration: underline;' href="http://www.koivi.com" target="_blank">http://www.koivi.com</a><!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: virtual hosts and root directory for php 
Back to top
Login to vote
news75

External


Since: Sep 23, 2004
Posts: 2



(Msg. 3) Posted: Fri Sep 24, 2004 3:32 am
Post subject: Re: virtual hosts and root directory for php [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Justin Koivisto wrote:

 > Christoph Hörterer wrote:
 >
  >> Hi,
  >> I'm using Apache 1.3.29 on Mac OS X for testing purposes. I achieved
  >> to create some virtual hosts.
  >>
  >> But when a file tries to php include() some file that is referred to
  >> like /include/file.txt (include("/include/file.txt")WinkI get errors:
  >>
   >>> Warning: main(/include/file.txt): failed to open stream: No such file
   >>> or directory in /Users/pofi/Sites/pofi.de/index.html on line 18
   >>>
   >>> Warning: main(): Failed opening '/include/file.txt' for inclusion
   >>> (include_path='.:/usr/lib/php') in
   >>> /Users/pofi/Sites/pofi.de/index.html on line 18
   >>>
  >>
  >>
  >>
  >> My virtual hosts config is e.g.
  >>
  >> <VirtualHost *>
  >> ServerName test.pofi.de
  >> DocumentRoot /Users/pofi/Sites/pofi.de
  >> </VirtualHost>
  >>
  >> Is there another directive to enable these paths? Or do I have to
  >> tweak the php.ini somewhere? Or did I make a mistake in php syntax?
 >
 >
 > easiest way...
 >
 > include dirname(__FILE__).'/include/file.txt';
 >
 > Where "/include/file.txt" is relative to the file that you are working on.
 >

Ok,
didn't really understand your answer but it brought me to something
obvious. Thank you. As virtual hosts already work, I just add the
virtual domain:

include("http://test.pofi.de/include/file.txt");

So it works, even in subdirectories.
How come that php doesn't accept the root directory of a virtual host,
while html and css does?

cu Christoph<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: virtual hosts and root directory for php 
Back to top
Login to vote
spam3

External


Since: Jul 01, 2003
Posts: 411



(Msg. 4) Posted: Fri Sep 24, 2004 4:06 pm
Post subject: Re: virtual hosts and root directory for php [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Christoph Hörterer wrote:
 > Justin Koivisto wrote:
 >
  >> Christoph Hörterer wrote:
  >>
   >>> But when a file tries to php include() some file that is referred to
   >>> like /include/file.txt (include("/include/file.txt")WinkI get errors:
   >>>
   >>>> Warning: main(/include/file.txt): failed to open stream: No such
   >>>> file or directory in /Users/pofi/Sites/pofi.de/index.html on line 18
   >>>>
   >>>> Warning: main(): Failed opening '/include/file.txt' for inclusion
   >>>> (include_path='.:/usr/lib/php') in
   >>>> /Users/pofi/Sites/pofi.de/index.html on line 18
   >>>>
   >>> Is there another directive to enable these paths? Or do I have to
   >>> tweak the php.ini somewhere? Or did I make a mistake in php syntax?
  >>
  >> easiest way...
  >>
  >> include dirname(__FILE__).'/include/file.txt';
  >>
  >> Where "/include/file.txt" is relative to the file that you are working
  >> on.
 >
 > Ok,
 > didn't really understand your answer but it brought me to something
 > obvious. Thank you. As virtual hosts already work, I just add the
 > virtual domain:
 >
 > include("http://test.pofi.de/include/file.txt");
 >
 > So it works, even in subdirectories.
 > How come that php doesn't accept the root directory of a virtual host,
 > while html and css does?

Because PHP uses the SYSTEM path, not the HTTP path. For instance, using
"http://test.pofi.de/include/file.php" will actually open the file via a
GET request to the server. Therefore, if you have function definitions
in that file, you won't have the function available for use in other files.

Quote from the PHP manual about include:
<quote>
If "URL fopen wrappers" are enabled in PHP (which they are in the
default configuration), you can specify the file to be included using an
URL (via HTTP or other supported wrapper - see Appendix I for a list of
protocols) instead of a local pathname. If the target server interprets
the target file as PHP code, variables may be passed to the included
file using an URL request string as used with HTTP GET. This is not
strictly speaking the same thing as including the file and having it
inherit the parent file's variable scope; the script is actually being
run on the remote server and the result is then being included into the
local script.
</quote>

In the example above, the file would actually be located at:
/Users/pofi/Sites/pofi.de/include/file.php

That is what PHP is expecting for a local pathname. Using
"dirname(__FILE__)" will return the "/Users/pofi/Sites/pofi.de" portion
for you if it is in a file in the DOCUMENT_ROOT. Doing the same in the
file.php would yield "/Users/pofi/Sites/pofi.de/include"

Also note that you can set your include_path that PHP uses to allow you
to simply do:
include "file.php"

In .htaccess or the VirtualHost directive, simply add a line like:
php_value include_path "/Users/pofi/Sites/pofi.de/include"

You could also do something similar in a PHP script:
$inc_path=ini_get('include_path');
ini_set('include_path',$path.':'.$_SERVER['DOCUMENT_ROOT'].'/include');

The thing to remember about css, javascript, html is that they are not
executed server-side, PHP is. That is why PHP expects a local file path
rather than a URI.

--
Justin Koivisto - spam.DeleteThis@koivi.com
<a style='text-decoration: underline;' href="http://www.koivi.com" target="_blank">http://www.koivi.com</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: virtual hosts and root directory for php 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
default directory in virtual hosts? - Hi, can i make an entry for a default Server in name based virtual hosts what will be used when no entry is found for the give domainname? For Apache 1.3.x !

Virtual hosts: 2 Domains that point to the same directory - Hi there I created two virtual hosts that have the same directory as the DocumentRoot: <VirtualHost *> DocumentRoot /web/html ServerName a.com </VirtualHost> <VirtualHost *> DocumentRoot /web/html Serve...

Virtual Hosts/Directory Index Forbidden by Rule - Hello all, can you help please? I am ditching using a win2K server for all sorts of reasons and am migrating to Linux RH9. My server is built and seems to work ok when I have a default site to serve with Apache 2.0.40. I have set my group and ownershi...

Web server root directory - Hello, I just installed apache and wanted to change my root directory to the directory where my homepage files are, but it sais an error that some modules are missing. Can't I just change the root directory for the server, and that apache just takes his...

Virtual host / document root - I am attempting to set up virtual hosts in apache2triad on win xp for local development but when I point my browser to my-domain.com I never go to my index.htm file but to the htdocs dir. Here is the httpd set up, could anyone tell me what's wrong with...
   Web Hosting and Web Master Forums (Home) -> Apache All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]