Advertisement

08.19.2007 at 04:40PM PDT, ID: 22773010
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Working in DocumentRoot after setting open_basedir

Asked by ZhaawZ in PHP Scripting Language, Apache Web Server

Tags: , ,

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/index.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_log");
  // ".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/newdir');
  echo (int)touch('newfile');
  echo (int)touch('/www/test/newfile');
?>

--------------------- 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
[+][-]08.19.2007 at 05:50PM PDT, ID: 19727587

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 01:32AM PDT, ID: 19728863

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 12:52PM PDT, ID: 19733159

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 12:59PM PDT, ID: 19733248

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 01:26PM PDT, ID: 19733456

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 01:28PM PDT, ID: 19733477

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, Apache Web Server
Tags: apache, custom_log, open_basedir
Sign Up Now!
Solution Provided By: dharmanerd
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.20.2007 at 01:37PM PDT, ID: 19733552

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628