Solved

Unable to mkdir() in up level directory

Posted on 2006-11-23
8
403 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 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