Page 1 of 1

PHP using Apache's document root (maybe)

Posted: Tue Jun 14, 2005 5:45 pm
by pickle
Hi All,

I just installed PHP on an OpenBSD box and I'm having a funky problem with PHP accessing the filesystem.

I'm trying to include/require files using an absolute file path "/var/www/htdocs/funclib.php". However, I'm getting an error saying there is no such file.

When I include with "funclib.php" it works.

The weird thing is that when I include "/htdocs/funclib.php", it works fine. There is no directory called htdocs at the root of this server.

Any ideas? I've always used filesystem paths when including files, but this seems to be a bastard union of a filesystem and an Apache document root path.

Thanks!

Posted: Tue Jun 14, 2005 9:34 pm
by Ambush Commander
Try this diagnostic code, and tell us the output:

Code: Select all

<?php

echo '/ expands to:'.realpath('/').'<br />';
echo 'funclib.php expands to:'.realpath('funclib.php').'<br />';

?>

Posted: Wed Jun 15, 2005 12:32 am
by Syranide
It's likely you have a virtual path or something like that setup, meaning that your root isn't the actual root, but the apachefolder. (e.g., it is possible to map /var/log to /log in apache etc)

Posted: Wed Jun 15, 2005 9:51 am
by pickle
The output from that code is:

Code: Select all

/ expands to:/
funclib.php expands to:/htdocs/funclib.php
Is there a config I can set somewhere (either in apache or PHP) that tells it to not use virtual paths?

Posted: Wed Jun 15, 2005 10:50 am
by pickle
Well, I think I figured out what the problem is. Turns out that on OpenBSD, Apache runs in a chroot jail. What that means is that you can make Apache think that the root of the server is /var/www/, or any other directory. Unfortunately, that also sets up the mapping for PHP, of '/' to '/var/www/', effectively stopping any access to the /tmp directory or anything else below '/var/www/'.

I'm not the server admin for this particular server, so this can't be fixed today anyway. (Just ask me how frustrating THAT is :evil:).

Thanks for your help guys.

- Dylan