PHP using Apache's document root (maybe)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

PHP using Apache's document root (maybe)

Post 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!
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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 />';

?>
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply