Solved

Unable to mkdir() in up level directory

Posted on 2006-11-23
8
405 Views
Last Modified: 2008-02-01
Hello, I'm running Plesk/Apache/PHP4 server. A website in the following directory:

/var/www/vhosts/mysite.com/httpdocs <- this is the root directory of mysite.com. I uploaded the following php script to the site:

<?
//var/www/vhosts/mysite.com/httpdocs/mkdir.php

if(mkdir('/var/www/vhosts/mysite.com/test/abc'))
echo "TRUE";
else
echo "FALSE";
?>

And then access it from mysite.com/mkdir.php. But it doesn't work. I got FALSE! The abc directory was not created.

1. The mode of /var/www/vhosts/mysite.com/test directory is 777
2. The user running PHP is "apache"
3. The PHP safe_mode = false
4. I tried to change user of /var/www/vhosts/mysite.com/test directory into apache or even nobody, still doesn't work.
5. There is no problem if I create directory under httpdocs directory. For example, I create a directory named "inside" via FTP: /var/www/vhosts/mysite.com/httpdocs/inside and than set its mode into 777. When I use mkdir('/var/www/vhosts/mysite.com/httpdocs/inside/abc') to create directory, it works.

Why it just doesn't work outside the httpdocs directory?

0
Comment
Question by:iProgram
  • 4
  • 3
8 Comments
 
LVL 13

Assisted Solution

by:rhickmott
rhickmott earned 100 total points
ID: 18002191
Process of Elimination?

if (is_dir('/var/www/vhosts/mysite.com/test/')) {
     echo("Directory Exists!<br/>");
     
     if (is_writable('/var/www/vhosts/mysite.com/test/') {
          echo("Directory can be written to!<br />");
              if(mkdir('/var/www/vhosts/mysite.com/test/abc/')) {
                    echo("Folder Created");
              } else {
                    echo("Folder <b>not</b> Created");
              }
     } else {
           echo("Directory <b>cannot</b> be written to!");
     }
} else {
    echo("Directory <b>does not</b> exist!");
}
0
 
LVL 1

Author Comment

by:iProgram
ID: 18002423
is_dir('/var/www/vhosts/mysite.com/test/') == FALSE. I created this directory via SSH. I also tried to change user name of test directory into apache but it's still FALSE.

By the way is_dir('/var/www/vhosts/mysite.com/httpdocs/') == TRUE.

It's really strange!
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18002457
This is where you have to be careful Apache can be extremely funny about which directory's it allows PHP Scripts ( And itself ) to access.

If you wrote a script to copy /etc/passwd the chances are it would tell you to go to hell. If you wrote an Alias to /etc/ it would merrily let you do it.

If I recall rightly you normally cant access files on the file-system NOT referenced in httpd.conf.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 48

Accepted Solution

by:
hernst42 earned 400 total points
ID: 18002475
try enabing a more detailed error-message with

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

if(mkdir('/var/www/vhosts/mysite.com/test/abc'))
echo "TRUE";
else
echo "FALSE";

What do you get as output ?
0
 
LVL 1

Author Comment

by:iProgram
ID: 18002561
I got this:

Warning: mkdir(): open_basedir restriction in effect. File(/var/www/vhosts/mysite.com/test/abc) is not within the allowed path(s):
(/var/www/vhosts/mysite.com/httpdocs:/tmp) in /var/www/vhosts/mysite.com/httpdocs/mkdir.php.php on line 5

This is a new plesk server and I'm just trying to move a site from a Cpanel server to it. The same script works fine on the Cpanel server. Is there a way to fix this issue?
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18002614
Hmmm open_basedir is normally a Safe Mode thing.
0
 
LVL 1

Author Comment

by:iProgram
ID: 18002715
Ok I found the answer and open_basedir is not only a safe mode param. Plesk defined the open_basedir for me and I have to write a new conf file for it.
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18002728
ah ok well thats ok then :)

I said *normally* fortunately Plesk is not a standard thing for most PHP set-ups so a lot of the time its due to a safe mode restriction.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question