Using Apache 2.2.4 with PHP 5.2.3 (as a module) on Slackware 11.
I tried to set open_basedir directive in virtual hosts, now I have some problems - PHP does not allow me to create files/directories directly in DocumentRoot, is_file(), is_dir() and other functions also fail in many cases.
--------------------- vhost example (from httpd.conf):
<VirtualHost *>
DocumentRoot /www/test
ServerName 192.168.0.7
ErrorLog /www/test/.logs/error_log
CustomLog /www/test/.logs/custom_log
custom_log
php_admin_value open_basedir /www/test/
</VirtualHost>
--------------------- PHP example (/www/test/index.php):
<?php
// ".logs" directory exists - no errors here
echo (int)is_file('.logs');
echo (int)is_dir('.logs');
echo (int)is_dir(getcwd() . '/.logs'); // "/www/test/.logs"
// "index.php" file also exists - no errors here
echo (int)is_file('index.php');
echo (int)is_dir('index.php');
echo (int)is_dir('/www/test/ind
ex.php');
// ".logs/error_log" file exists (and is a file) - no problem here
echo (int)is_file(".logs/error_
log");
echo (int)is_dir(".logs/error_l
og");
// ".logs/test" does not exist - no problem here though, since it's not directly in "/www/test/"
echo (int)is_file(".logs/test")
;
echo (int)is_dir(".logs/test");
// now the "interesting" part - everything fails, it says that "open_basedir restriction in effect"
// "." and "/www/test/" are currend directory
// "newdir" is a directory that does not exist (in ".")
// "newfile" is a file that does not exist (in ".")
echo (int)is_dir('.');
echo (int)is_dir('/www/test/');
echo (int)mkdir('newdir');
echo (int)mkdir('/www/test/newd
ir');
echo (int)touch('newfile');
echo (int)touch('/www/test/newf
ile');
?>
--------------------- Output:
0111001000
Warning: is_dir() [function.is-dir]: open_basedir restriction in effect. File(.) is not within the allowed path(s): (/www/test/) in /www/test/index.php on line 20
0
Warning: is_dir() [function.is-dir]: open_basedir restriction in effect. File(/www/test/) is not within the allowed path(s): (/www/test/) in /www/test/index.php on line 21
0
Warning: mkdir() [function.mkdir]: open_basedir restriction in effect. File(newdir) is not within the allowed path(s): (/www/test/) in /www/test/index.php on line 22
0
Warning: mkdir() [function.mkdir]: open_basedir restriction in effect. File(/www/test/newdir) is not within the allowed path(s): (/www/test/) in /www/test/index.php on line 23
0
Warning: touch() [function.touch]: open_basedir restriction in effect. File(newfile) is not within the allowed path(s): (/www/test/) in /www/test/index.php on line 24
0
Warning: touch() [function.touch]: open_basedir restriction in effect. File(/www/test/newfile) is not within the allowed path(s): (/www/test/) in /www/test/index.php on line 25
0
It's "a bit annoying" to look at those "File(/www/test/) is not within the allowed path(s): (/www/test/)", since /www/test/ IS /www/test/, isn't it? Also file_exists() works with "somefile" if it exists, but throws "open_basedir restriction in effect" warning if it does not exist. Creating directories/files in DocumentRoot also does not work.
Everything works fine if I set "/www/test" (without ending slash) as open_basedir, but this is not desirable, since "/www/test" would mean also "/www/test1/", "/www/test2/", "/www/testing/" etc.
Any idea why does PHP act like this? What could I do to solve this?
Start Free Trial